sisense/graphql2rest

Hangs on large schema?

crubier opened this issue · 2 comments

I have a pretty large GraphQL schema (schema-main.graphql is 107kloc) and the generation hangs out at thi stage:

info: GQLGenerator initializing...
info: GQLGenerator initialized with query depthLimit of 1000
info: [gqlgenerator] Creating folder /Users/vincent/Code/sterblue1/packages/apps/graphile/src/rest/generated-graphql-files/

Here is the TS file being executed:

import GraphQL2REST from "graphql2rest";
import { execute } from "graphql"; // or any GraphQL execute function (assumes apollo-link by default)
import { buildSchema } from "graphql";
import path from "path";
import fs from "fs";

const schema = buildSchema(
  fs.readFileSync(path.resolve(__dirname, "../../schema-main.graphql"), {
    encoding: "utf8"
  })
);

const gqlGeneratorOutputFolder = path.resolve(
  __dirname,
  "./generated-graphql-files"
);
const manifestFile = path.resolve(__dirname, "./manifest.json");

export const restRouter = GraphQL2REST.generateGqlQueryFiles(
  schema,
  gqlGeneratorOutputFolder
); 

Ok it looks like it was the depthLimitArg of the generateGqlQueryFiles function call which is by default at 1000, which seems way too high. A default of 5 sounds better than 1000

Hi @crubier, thanks for using graphql2rest and thanks for opening an issue.

The query depth limit can indeed be configured by setting the depthLimitArg parameter in generateGqlQueryFiles() (one of that function's optional params), as described in the documentation.

Based on your feedback I reduced the default depth to 100, because 1000 indeed seems too high and make the pre-process step very slow. 5 might work for you but it seems too low for the general use case. Some users might still need to make it smaller (depending on their schema), but a value of 100 seems safe as a default. Thank you!