Skip to content
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

Schema not getting updated after instantiation #5106

Closed
AienTech opened this issue Apr 12, 2021 · 1 comment
Closed

Schema not getting updated after instantiation #5106

AienTech opened this issue Apr 12, 2021 · 1 comment

Comments

@AienTech
Copy link

Basically after the server is instantiated, the schema change process won't run and thus resolvers aren't getting updated.

The issue actually happens in a CMS where, after the user changed the schema, we should update the server accordingly so that introspection and resolving work.

here's a sample of how the process takes effect:

// initial build
let external;

let externalServer: any = new ApolloServer({
    introspection: true,
    playground: true,
    schema: buildSchema(`type Query { boot: Boolean }`),
});

pubSub.subscribe("REBUILD_EXTERNAL", async(payload) => {
    external = await createExternal(connection);  // this function creates the new schema and the context after a change
    externalServer.schema = external.schema;
    externalServer.context = external.context;
    externalServer.schemaDerivedData = externalServer.generateSchemaDerivedData(external.schema);
});

// to update the schema after first initialization
pubSub.publish("REBUILD_EXTERNAL", {
    name: "SERVER_BOOT"
});

externalServer.applyMiddleware({
    app,
    path: `${config.path}graphql`,
        cors: {
            origin: true,
        },
});

this issue is actually taken from PrimeCMS with some small changes for better readability.

@glasser
Copy link
Member

glasser commented Apr 14, 2021

Updating these fields to change the schema is not part of the Apollo Server API. We refactored the internal storage of these fields in v2.22.

If you want to update your schema over time, you can create an object that obeys the GraphQLService API including the onSchemaChange method and pass it as the gateway argument. While this is designed for use with @apollo/gateway, it is an API that does work with your own objects.

It might also be reasonable for us to expose a public API to let you set your schema that does

      if (this.state.phase === 'started') {
        this.state.schemaDerivedData = this.generateSchemaDerivedData(schema);
      }

just like the onSchemaChange callback.

But this is for now working as intended.

@glasser glasser closed this as completed Apr 14, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants