timqian / gql-generator

Generate queries from graphql schema, used for writing api test.
MIT License
376 stars 93 forks source link

flag to support buildSchema assumeValidSDL param #57

Closed SamuelGHill closed 2 years ago

SamuelGHill commented 2 years ago

Allows for custom types and directives to be involved in a schema. Is currently supported in graphql BuildSchema --> https://github.com/graphql/graphql-js/issues/1854#issuecomment-490353851

I am using gql-generator to build out query samples, and we use custom types and directives in our schemas. We do not need the validator.

With this PR, the CLI can add this flag, --assumeValid true

gqlg --schemaFilePath index.graphql --destDirPath ./example/output --depthLimit 5 --assumeValid true

Error: Unknown directive "@rest".
    at assertValidSDL (/Users/samuelhill/Desktop/app/node_modules/graphql/validation/validate.js:135:11)
    at buildASTSchema (/Users/samuelhill/Desktop/app/node_modules/graphql/utilities/buildASTSchema.js:44:34)
    at buildSchema (/Users/samuelhill/Desktop/app/node_modules/graphql/utilities/buildASTSchema.js:109:10)
    at Object.<anonymous> (/Users/samuelhill/Desktop/app/node_modules/gql-generator/index.js:28:19)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
SamuelGHill commented 2 years ago

Passes tests -->

$ npm run test

> gql-generator@1.0.15 test
> mocha -u qunit

  ✓ validate generated queries (246ms)
  ✓ limit depth (338ms)
  ✓ excludes deprecated fields by default (180ms)
  ✓ includes deprecated fields with includeDeprecatedFields flag (172ms)
  ✓ includes nested in union types (179ms)

  5 passing (1s)