Schema stitching when remote schema updates #791
-
/label discussion If I am doing schema stitching from remote schemas and one of the schemas gets updated do I need to restart my service to get the new schemas? or should I be doing some sort of polling to figure out if the schemas have changed and or is there a better way to handle this pattern? my code looks something like const link = new HttpLink({ uri: URI, fetch })
const schema = await introspectSchema(link)
const remoteSchema = makeRemoteExecutableSchema({
schema,
link
})
return usersSchema
const server = new GraphQLServer({
schema: remoteSchema
})
server.start({port: 3000}) |
Beta Was this translation helpful? Give feedback.
Replies: 15 comments
-
Anyone have thoughts? |
Beta Was this translation helpful? Give feedback.
-
@krisread Yah I like the idea of a schema version. I don't think anything has to automatically sync or retry but if the response always included a version then the client could respond as they deem necessary. For example if there is no error but the schema version doesn't match, maybe an async retrieval of the new schema would be good, but in a case where there are errors and a different schema it would be good to sync the schemas and retry the request. |
Beta Was this translation helpful? Give feedback.
-
After talking with some more people about this I have changed my opinion on it. I think the point of Graphql is to be versionless. In an ideal world you would never make breaking changes to the schema, you would just deprecate things and monitor for when most people stop using them and then remove them. AirBnb has a good talk about their graphql API tier where they briefly touch on how they do schema updates: https://youtu.be/tSoEAjvvtYI?t=21m6s |
Beta Was this translation helpful? Give feedback.
-
Any update on this, running into similar issue - The temporary work around is to bounce our gateway server with every downstream deployment. This is not ideal |
Beta Was this translation helpful? Give feedback.
-
Would love to see something from Apollo to solve this - relying on deployments to re-introspect downstream schemas is not ideal. Some other options we are looking at:
None of which feel like the complete solution. |
Beta Was this translation helpful? Give feedback.
-
Still looking for a better solution for this. When wrapping a remote schema that you do not control, it would be nice to have an easy way to update the schema when something changes. |
Beta Was this translation helpful? Give feedback.
-
2019 and it is still a relevant topic here. |
Beta Was this translation helpful? Give feedback.
-
I've started adding an extra HTTP header that gives the startup time of the downstream service. The upstream aggregator tracks the latest startup times and polls with HEAD occasionally, and if it sees a later startup time, it re-introspects and reconstructs the upstream schema. A tad ugly, but nice when it works. |
Beta Was this translation helpful? Give feedback.
-
Any news about this ? |
Beta Was this translation helpful? Give feedback.
-
When you know that you have to re-instrospect the downstream schema how you update the schemas loaded into the server? are you restarting it? if you have some example of this, will be usefull to me |
Beta Was this translation helpful? Give feedback.
-
If you want to upgrade schema in runtime for Apollo Server, you can just do this: const schema = await createSchema()
// Got schema derived data from private ApolloServer method
// @ts-ignore
const schemaDerivedData = await apolloServer.generateSchemaDerivedData(
schema,
)
// Set new schema
set(apolloServer, 'schema', schema)
// Set new schema derived data
set(apolloServer, 'schemaDerivedData', schemaDerivedData) And all refresh stuff will work like a charm |
Beta Was this translation helpful? Give feedback.
-
what is the |
Beta Was this translation helpful? Give feedback.
-
It's from lodash, looks something like this import set from 'lodash/set';
...
const server = new ApolloServer(config);
setInterval(async () => {
const newSchema = await createRemoteSchemas();
const schemaDerivedData = await server.generateSchemaDerivedData(newSchema);
set(server, 'schema', newSchema);
set(server, 'schemaDerivedData', schemaDerivedData);
}, POLLING_INTERVAL_IN_MS);
... |
Beta Was this translation helpful? Give feedback.
-
We are having a discussion about this here: #2022 just in case you guys want to pitch in. |
Beta Was this translation helpful? Give feedback.
-
Take a look at this: gmac/schema-stitching-handbook#3 |
Beta Was this translation helpful? Give feedback.
Take a look at this: gmac/schema-stitching-handbook#3