Closed victorandree closed 1 year ago
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.
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!
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.
@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!
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
As the author of the issue, I'm going to close it, since the project appears abandoned.
This is used by graphql-tools to modularize, primarily, the main
Query
type:Would be great if this were supported. The
extend
keyword seems undocumented but is parsed as part of the AST, producing aTypeExtensionDefinition
object, which then holds a regularObjectTypeDefinition
.graphql
includes a utility functiongraphql/utilities/extendSchema
to support extensions. It appears likegraphql-tools
uses the graphql provided functionextendSchema
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 ownGQLSchema
instance.extendSchema
checks that the passed instance is aGraphQLSchema
-- so it fails. It may be the case that you have to use a patched version ofextendSchema
as well, then...I'd be willing to look into a patch if there's interest.