Home > Back-end >  How to disable introspection and load a schema from a String in WunderGraph?
How to disable introspection and load a schema from a String in WunderGraph?

Time:12-06

I am currently building a full stack application and having some performance issues with my service due to introspection. I would like to disable introspection for some services and rather load my schema using a string.

I tried looking at the documentation and followed along the steps to solve it but when I load it from a string, the service is still being accessed by WunderGraph.

CodePudding user response:

To disable introspection and load a schema from a string in WunderGraph, you can follow these steps:

First, create a GraphQL schema as a string. This can be done by defining your schema using the GraphQL schema language and converting it to a string using the print or printSchema utility from the graphql package.

const schemaString = `
  type Query {
    hello: String
  }
`;

Next, pass the schema string to the buildSchema function from the graphql package. This will create a GraphQLSchema instance from the schema string.

const schema = buildSchema(schemaString);

Finally, you can pass the schema instance to the WunderGraph constructor when creating a new instance of the WunderGraph client. This will tell WunderGraph to use the provided schema instead of performing introspection.

const wunderGraph = new WunderGraph({
  schema,
});

Once you have done this, WunderGraph will use the provided schema and will not perform introspection on your GraphQL service. This should improve the performance of your application and prevent the service from being accessed by WunderGraph.

CodePudding user response:

You can use loadSchemaFromString for this:

const api = introspect.graphql({
    loadSchemaFromString: '',
})
  • Related