Will Lo
Will Lo

Reputation: 1

Can I update the GraphQL Schema?

```app.use("/graphql", expressGraphQL({
  schema: schema,
  graphiql: true,
}))```

I am developing a Quick schema builder, therefore, I hope the schema can be edited. I declared the schema as a variable, I added some functionality to update the schema. However, no matter what the new stuff I added, the path (./graphql) wont read it. just remember the first schema.

is there any way to do the same thing?

Upvotes: 0

Views: 5103

Answers (1)

Manny
Manny

Reputation: 389

UPDATE: OP was asking about hot reload of a schema

This is discussed here: https://github.com/apollographql/apollo-server/issues/1275#issuecomment-513364165


Old Answer

Making the assumption that schema is the response from buildSchema. schema cannot be updated directly via adding additional SDL text without first calling printSchema(), passing in schema, which returns an SDL representation of the schema.


const sdlSchema = printSchema(schema);
sdlSchema +=`
type Book {
  title: string
  color: string
}
`
const newBuiltSchema = buildSchema(sdlSchema);
app.use("/graphql", expressGraphQL({
  schema: newBuiltSchema,
  graphiql: true,
}))

This SDL schema may be updated by appending additional SDL compliant GraphQL definitions.

//ex.

type Book {
  title: string
  color: string
}

// or query or mutation

Upvotes: 1

Related Questions