-
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
Allow schemaPrinter to be customized / extended. #2020
Comments
Instead of making an extensible printer, would it solve your issue if directives on schema definitions were included in the print step? I believe this is actually a bug where we forgot to add directive printing for |
@j @mjmahone I don't think we should print directives based on type Foo {
foo: String
}
type Bar @copyFields(fromType: "Foo") {
bar: String
} Assuming type Foo {
foo: String
}
type Bar @copyFields(fromType: "Foo") {
foo: String
bar: String
} That doesn't make sense in the context of I think the correct solution would be to design This solution also solves the problem of code-first schema that wants to be printed with additional data represented as directives in SDL. |
That definitely sounds like a much better solution. I was just noticing other libraries are simply copy/pasting schema printer to do their own logic and pull out directives as their library has them. I'm super excited for this change as it'll marry everyone's wishes (having directives :P) I've been working on implementing Ref: MichalLytek/type-graphql#369 apollographql/apollo-server#3013 |
Found this after I made Looking forward to 16.0.0 for a more elegant solution! |
@IvanGoncharov What if type Foo {
foo: String
}
type Bar @copyFields(fromType: "Foo") {
bar: String
} // 1
printSchema(makeExecutableSchema({
typeDefs,
schemaDirectives: {
copyFields: CopyFieldsVisitor
}
}))
// 2
printSchema(makeExecutableSchema({
typeDefs,
schemaDirectives: {
}
})) The first snippet would print: type Foo {
foo: String
}
type Bar {
foo: String
bar: String
} The second would print: type Foo {
foo: String
}
type Bar @copyFields(fromType: "Foo") {
bar: String
} |
At least printing the directives would help me immensely, thins like input field, field, object, input object declarations for validation and permission annotations via directives would just work. But if we need to provide a custom printer, that's also ok. |
How about we add a config option: printDirectives: (definition: GraphQLType|GraphQLField|GraphQLEnumValue|GraphQLInputField|GraphQLArgument) => string Whenever a definition that can hold directives is encountered, the given function would be called with it and is free to print any directives. |
@spawnia Will it by any chance be possible that I can make use of the utilities available internally to |
I'd also be really interested in a solution here! Stumbled upon #2145 (comment) while searching around, which seems to at least offer a workaround (will have to test that). And I found this comment, which received quite some upvotes: #869 (comment) Would that still be the way to "polyfill" this when printing a schema? Use-case here is printing a "Gatsby-compatible" schema, which includes adding some directives used by Gatsby (like |
@julrich My |
I'll have look, thanks! But I'm not sure that it would address my use-case. |
Oh I thought |
Resolves graphql#2020 I initially thought about implementing this as graphql#2020 (comment), but really could not think of a good use case where a directive should be printed in a modified way. Thus, I went for a simpler signature: ```ts shouldPrintDirective?: (directiveNode: DirectiveNode) => boolean ``` This is only a partial implementation for now, there are more possible locations in a schema that can have a directive. Before I finish the implementation, I would like to validate the direction is right.
Some libraries are having to copy the schemaPrinter code to do custom stuff to the output, (
@apollo/federation
,type-graphql
). These libraries require outputting type and field level directives since this isn't supported in this library. Is there any support to do so, or can the schemPrinter just export the other functions so we don't have to copy every function or, even better, create a SchemaPrinter class so everything can be over-ridden, thenprintSchema
options can set the printer for BC:The text was updated successfully, but these errors were encountered: