-
Notifications
You must be signed in to change notification settings - Fork 2k
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
printSchema loses @directive information #869
Comments
This is correct behavior. Directives are artifacts of the GraphQL language, and not properties of a GraphQL schema. While directives are allowed to be used in the GraphQL schema language, they exist as language-level metadata which different tools may interpret in different ways. For example, as you pointed out However the opposite is not the case. Since a schema is an in-memory data structure artifact, and not simply a representation of the GraphQL language, it does not have a concept of directives on its own. Though utilities like However to your example, |
IMO lacking of mechanism to transmit any metadata in schema (even descriptions are stripped off) is a serious flaw and actually its hard for me to understand described harm. |
@mrjj Agree, but this issue is beyond the scope of |
@IvanGoncharov the issue that during 2 last years of development resources are investing in parser, but not in language and seeing parser and schema description language as a different things with different policy is completely shizophenic.
Every day students write a ten new parsers even with formal grammar description support and other bells and whistles. They have no value. Value is in maintaining industry standards that are comfortable to use, have working reference implementation, extendable and through this making integration and development easy. I don't expect that e.g. Brotobufs or SOAP or RDP or whatever extensions being defined in standards will be intentionally restricted in reference implementation to make it non-extandable by no reason. Standards covering e.g. JSONSchema or Thrift are not separated on syntax and language, they are just JSONSchema or Thrift standards and every implementation just implementing this standard from 1% to 200% and reference implementation is you know reference for this. |
If you want to reproduce the definition along with the directives you can just print all the astNodes. import { print, isSpecifiedScalarType, isSpecifiedDirective } from 'graphql';
export function printSchemaWithDirectives(schema) {
const str = Object
.keys(schema.getTypeMap())
.filter(k => !k.match(/^__/))
.reduce((accum, name) => {
const type = schema.getType(name);
return !isSpecifiedScalarType(type)
? accum += `${print(type.astNode)}\n`
: accum;
}, '');
return schema
.getDirectives()
.reduce((accum, d) => {
return !isSpecifiedDirective(d)
? accum += `${print(d.astNode)}\n`
: accum;
}, str + `${print(schema.astNode)}\n`);
} |
@bhoriuchi Great snippets, do you think it's possible to also convert comment descriptions? I was using AWS AppSync has their own custom directives, but their GraphQL engine is also ancient. It does not support type extension, uses comment descriptions, hiccups left and right... |
@vicary I'm not sure as I have no experience with AppSync. The code I provided relies on the native graphql-js print function but you can get the description from the astNode and add it in if its not being printed. https://github.com/graphql/graphql-js/blob/master/src/language/ast.js#L540 |
@bhoriuchi Thanks! I wanted description of type defs instead of directive defs, but I get the idea. I also noticed that all of my |
Ended up digging too deep and creating |
I've fixed this issue with the method printschemawithdirectives from graphql-tools library. I hope this helps! 😄 |
Hey @vicary, how did you end up fixing this issue in your appsync-schema-converter where it removes "extend type"? I was actually planning to create an AppSync converter myself, but specifically for subgraphs with Apollo Federation. Maybe something that could be built into your package instead though! |
@mkossoris I am not familiar with federation, let me know which particular feature you'd like to see in appsync-schema-converter I'll make it happen. My team is using my converter in production for a couple of years now, it should be stable enough for most cases. |
@vicary I went ahead and created an issue in your GitLab repo here: https://gitlab.com/vicary/appsync-schema-converter/-/issues/2 |
@mkossoris I've made a MR !11 to include types for Apollo Federation Subgraphs. Let's test it out and I'll release a new minor. OT: I am also reviving GQty the GraphQL client with upcoming plans. The DX really beats everything else in the market, check it out! Screen_Recording_2023-04-07_at_20.24.16.mov |
Hi, the printSchema function in "graphql/utilities/schemaPrinter" seems to forget the directives on field definitions.
current output:
expected output:
Tested against graphql version: 0.9.6
I already digged a bit deeper into schemaPrinter and it seems that there is some special handling for directives going on:
1.) printSchema filters directives down to "skip", "include" and "deprecated"
2.) @ deperected seems to be handled
This is maybe better addressed in a separate issue, but I would like to add my own custom directives and get them also properly handled by printSchema.
Would you consider a PR for proper handling of spec directives as well as custom ones?
The text was updated successfully, but these errors were encountered: