Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

@cypher doesn't work in extend type Query #395

Closed
mohamedGamalAbuGalala opened this issue Feb 17, 2020 · 3 comments
Closed

@cypher doesn't work in extend type Query #395

mohamedGamalAbuGalala opened this issue Feb 17, 2020 · 3 comments

Comments

@mohamedGamalAbuGalala
Copy link

Description

When you have such a big schema to design you might need to split your schema into multiple files instead of a single one.
We split the files to one base file that has all base (Query, Mutation, Subscription) types and all other files extend these types if they need.
The problem came when we need to extend the type Query and use @cypher inside it.

The problem
@cypher didn't work as expected in the extend type Query and only work on the root Query type

Here is a sample repo for this issue

Sample Code

const typeDefs = `
type Query {
  rootQuery: String @cypher(statement: "WITH 'Wooorking 🐈 🐈 🐈 🐈' AS value RETURN value")
 }

 type Movie {
  title: String
  movieTestBase: String @cypher(statement: "WITH 'Wooorking 🐈 🐈 🐈 🐈' AS value RETURN value")
 }

 extend type Movie {
  movieTestExtend: String @cypher(statement: "WITH 'Wooorking 🐈 🐈 🐈 🐈' AS value RETURN value")
 }

 extend type Query {
  extendQuery: String @cypher(statement: "WITH 'NOT WORKING 😞 😞 😞 😞' AS value RETURN value")
 }
`
@benjamin-rood
Copy link

benjamin-rood commented Apr 2, 2020

Workaround:

Use mergeTypeDefs function from the @graphql-toolkit/schema-merging module, it will merge type extensions together, then you use print from graphql.js to export the typedefs back into an SDL string.

Which you can then pass back into makeAugmentedSchema.

pseudocode:

import { mergeTypeDefs } from '@graphql-toolkit/schema-merging';
import { print } from 'graphql';

const a = `type Query {
  rootQuery: String @cypher(statement: "WITH 'Wooorking 🐈 🐈 🐈 🐈' AS value RETURN value")
 }`;
const b = ` type Movie {
  title: String
  movieTestBase: String @cypher(statement: "WITH 'Wooorking 🐈 🐈 🐈 🐈' AS value RETURN value")
 }`;
const c = `extend type Movie {
  movieTestExtend: String @cypher(statement: "WITH 'Wooorking 🐈 🐈 🐈 🐈' AS value RETURN value")
 }`;
const d = `extend type Query {
  extendQuery: String @cypher(statement: "WITH 'NOT WORKING 😞 😞 😞 😞' AS value RETURN value")
 }
`;
const tdList = [a, b, c, d];
return print(mergeTypeDefs(tdlist));

@mohamedGamalAbuGalala
Copy link
Author

Thanks, I'll try your solution ❤️

@johnymontana
Copy link
Contributor

This should be fixed now (by #418) and we include this scenario in the test here

Please reopen if you're still seeing problems with this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants