[graphql-js] require opt-in to allow defer/stream #12
Replies: 6 comments 23 replies
-
@glasser The |
Beta Was this translation helpful? Give feedback.
-
Also @tgriesser @Sytten for Nexus. |
Beta Was this translation helpful? Give feedback.
-
Since the original discussion got a bit heated, emotional, and too vague (picking certain aspects and ignoring others), I tried to gather all mentioned ideas and concerns, outline the pros and cons, while also adding my personal conclusion. The problemThe core question that started the debate is the following:
Use-case: apollo-server wants to support the latest graphql-js versions as a (peer-)dependency as soon as possible, without the need to support all the new features supported by it, like incremental delivery. Proposed Solutions1. Feature Flag within graphql-js GraphQLSchemaWith those requirements in mind, the idea came up to disable The default value of const schema = new GraphQLSchema({
enableDeferStream: true,
...remainingParams,
}); This flag modifies the const schema = new GraphQLSchema({
enableDeferStream: true,
// incrementalDelivery: true will result in adding the stream directive anyways
// -> It is impossible to only allow defer or stream this way.
directive: specifiedDirectives.filter((directive) => directive.name !== “stream”),
}); Pros:
Cons:
2. Assert the GraphQL schema with codetype ServerArgs = {
schema: GraphQLSchema
port?: number
hostname?: string
}
function createServer({ schema, ...rest }: ServerArgs) {
if (schema.getDirectives().some(directive => directive.name === "defer" || directive.name === "stream")) {
throw new Error("This framework does not support defer and stream.")
}
/// ... other logic
createHTTPServer()
} Pros:
Cons:
3. Filter the GraphQL schema with codetype ServerArgs = {
schema: GraphQLSchema
port?: number
hostname?: string
}
function createServer({ schema: inputSchema, ...rest }: ServerArgs) {
const schemaConfig = inputSchema.toConfig()
schemaConfig.directives = directives.filter(directive => directive.name !== "defer" && directive.name !== "stream"))
const schema = new GraphQLSchema({ ...schemaConfig })
/// ... other logic
createHTTPServer()
} Pros:
Cons:
4. Feature Flag for
|
Beta Was this translation helpful? Give feedback.
-
@IvanGoncharov @n1ru4l @saihaj @maraisr @glasser I added this to the agenda of the next GraphQL-JS WG meeting on Jan 26. |
Beta Was this translation helpful? Give feedback.
-
The result from the Working Group discussion:
|
Beta Was this translation helpful? Give feedback.
-
What would be the correct way for users who use SDL schemas to enable directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT
directive @stream(if: Boolean, label: String, initialCount: Int = 0) on FIELD
# rest of schema
type Query {
} As mentioned previously, this leaves room for error, as the directive definition should match exactly what is in the spec and what graphql-js is expecting. There is a private function import {GraphQLDeferDirective, GraphQLStreamDirective, printDirective} from 'graphql';
const schema = `
${printDirective(GraphQLDeferDirective)}
${printDirective(GraphQLStreamDirective)}
# rest of schema
type Query {
}
`; |
Beta Was this translation helpful? Give feedback.
-
Context
asked by @glasser graphql/graphql-js#2848 (comment)
Decision
Consequences
Beta Was this translation helpful? Give feedback.
All reactions