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

Type extensions not working #208

Closed
danielmcmillan opened this issue Feb 26, 2019 · 4 comments
Closed

Type extensions not working #208

danielmcmillan opened this issue Feb 26, 2019 · 4 comments

Comments

@danielmcmillan
Copy link

If you have a schema definition that includes type extensions, e.g.

type Query {
  something
}
extend type Query {
  somethingElse
}

makeAugmentedSchema will fail with an error "Cannot extend type "Query" because it does not exist in the existing schema." (looks like extractTypeMapFromTypeDefs replaces the initial type definition since the second one has the same name).

makeExecutableSchema of graphql-tools will build a schema that includes the type extensions.
augmentSchema will ignore those type extensions and the resulting schema will only include the base type. (looks like extractTypeMapFromSchema takes astNode but ignores the extensionASTNodes array of GraphQLObjectType).

@JackDapid
Copy link

yes, same experience here

@johnymontana
Copy link
Contributor

A possible workaround from @benjamin-rood

Benjamin Rood  9 hours ago
FYI if anyone encounters this, I got around it by using 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. (edited) 

Benjamin Rood  9 hours ago
Which then you can then pass into makeAugmentedSchema :slightly_smiling_face:

@benjamin-rood
Copy link

@johnymontana

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));

@johnymontana
Copy link
Contributor

This should be fixed now (by #418) Please reopen if you're still having 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

4 participants