Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extend type #45

Closed
victorandree opened this issue Aug 14, 2017 · 6 comments
Closed

Support extend type #45

victorandree opened this issue Aug 14, 2017 · 6 comments
Milestone

Comments

@victorandree
Copy link

victorandree commented Aug 14, 2017

This is used by graphql-tools to modularize, primarily, the main Query type:

type Query {
  bars: [Bar]!
}

type Bar {
  id: String!
}

type Foo {
  id: String!
}
extend type Query {
  foos: [Foo]!
}

Would be great if this were supported. The extend keyword seems undocumented but is parsed as part of the AST, producing a TypeExtensionDefinition object, which then holds a regular ObjectTypeDefinition.

graphql includes a utility function graphql/utilities/extendSchema to support extensions. It appears like graphql-tools uses the graphql provided function extendSchema as part of building its complete schema. It should be possible to use similar logic as https://github.com/apollographql/graphql-tools/blob/master/src/schemaGenerator.ts#L147 to utilize these extensions (maybe even use the schema generator from graphql-tools?).

However, this project uses a patched version of buildASTSchema to generate its own GQLSchema instance. extendSchema checks that the passed instance is a GraphQLSchema -- so it fails. It may be the case that you have to use a patched version of extendSchema as well, then...

I'd be willing to look into a patch if there's interest.

@Mayank1791989 Mayank1791989 added this to the v3 milestone Aug 19, 2017
@Mayank1791989
Copy link
Owner

Looks valid will fix in next release.

maybe even use the schema generator from graphql-tools?

Its not possible as it throws if there is any error which is bad for language service, so need to implement patched version of extendSchema.

Mayank1791989 added a commit that referenced this issue Apr 18, 2018
BREAKING_CHANGE: structure of .gqlconfig file changed.

closes #3, closes #23, closes #28, closes #45, closes #52, closes #62, closes #99, closes #100, closes #115
Mayank1791989 added a commit that referenced this issue Apr 30, 2018
BREAKING_CHANGE: structure of .gqlconfig file changed.

closes #3, closes #23, closes #28, closes #45, closes #52, closes #62, closes #99, closes #100, closes #115
@lensbart
Copy link

Hi,

Thanks for creating this tool. It looks like the issue has been fixed in the commits of April 2018, but v3 hasn’t been released yet. Do you have an estimate as to when it might get released?

Thanks again!

@allesklarbeidir
Copy link

allesklarbeidir commented May 14, 2020

I think this is a big issue because at least I find myself using "extend TYPE" quite often and I can imagine other people doing that as well. At first I thought the graphql-for-vscode was not working because I didn't get any autocompletions and then I found out that the "extend TYPE" breaks it.

I dove into the source and just added some lines of code and now it's working for me. That's kind of a "quick and dirty fix" and I don't know if that introduces other issues but I highly doubt it, because as @victorandree mentioned the AST generated from "extend TYPE" is just the same "ObjectTypeDefinition" as usual but wrapped in a "TypeExtensionDefinition":

{
    "kind": "TypeExtensionDefinition",
    "definition": {
        "kind": "ObjectTypeDefinition",
     .....
     }
}

So adding

case 'TypeExtensionDefinition': {
    const _d = d.definition;
    const name = _d.name.value;
    if (!nodeMap[name]) {
      typeDefs.push(_d);
      nodeMap[name] = _d;
    } else {
      const existingTd = typeDefs.filter((td) => td.name.value === name)[0] || null;
      if (existingTd) {
        existingTd.fields = [].concat(...[...existingTd.fields, (_d.fields || [])]);
      }
    }
    break;
}

in buildASTSchema.js#L162 should fix the issue..

I will leave the hint here and add the fix to a fork / open a PR as soon as I got time to do so.

You can use "yarn add -D allesklarbeidir/gql" if you want to test it right now.

@lensbart
Copy link

@Mayank1791989 Apologies for bothering you with this, but would it be possible to incorporate the proposed changes so that @playlyfe/gql can work with schema stitching? This will help kumar-harsh.graphql-for-vscode (300.000+ installs in VSCode) to enable schema stitching as well.

Please let me know if I can be of any assistance.

Thanks in advance!

@arackaf
Copy link

arackaf commented Jun 29, 2021

For those winding up here, trying to get your VS Code plugin working, it looks like this project is largely abandoned, with a more current alternate plugin here:

https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql

@victorandree
Copy link
Author

As the author of the issue, I'm going to close it, since the project appears abandoned.

@victorandree victorandree closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants