directus / v8-archive

Directus Database API — Wraps Custom SQL Databases with a REST/GraphQL API
https://docs.directus.io/api/reference.html
505 stars 204 forks source link

GraphQL Schema Syntax Error using Graphql code generator #2104

Open fveracoechea opened 3 years ago

fveracoechea commented 3 years ago

Hello, First of all, I just want to say thanks for developing and maintaining such a great open source project!

I was trying to use Graphql Code Generator to generate some Typescript types and react hooks.

I successfully downloaded the schema using this command: get-graphql-schema https://my-project.com/directus/gql?access_token=API_TOKEN > ./graphql/schema.gql Then, when I ran the graphql-code-generator command I've got this issue:


fveracoechea@MacBook-Pro  ~/Code/fveracoechea-website   master ●  yarn codegenyarn run v1.22.4$ graphql-codegen --config codegen.yml ✔ Parse configuration ❯ Generate outputs ❯ Generate ./graphql/codegen.tsx ✖ Load GraphQL schemas → Failed to load schema Load GraphQL documents Generate

Found 1 error

✖ ./graphql/codegen.tsx Failed to load schema from ./graphql/schema.gql:

    Syntax Error: Invalid number, expected digit but got: "f".
    GraphQLError: Syntax Error: Invalid number, expected digit but got: "f".
at syntaxError (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/error/syntaxError.js:15:10)
at readNumber (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/lexer.js:400:40)
at readToken (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/lexer.js:258:14)
at Lexer.lookahead (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/lexer.js:75:108)
at Lexer.advance (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/lexer.js:58:35)
at Parser.expectToken (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:1418:19)
at Parser.parseName (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:92:22)
at Parser.parseNamedType (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:668:18)
at Parser.parseTypeReference (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:646:19)
at Parser.parseInputValueDef (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:903:21)
at Parser.optionalMany (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:1516:28)
at Parser.parseInputFieldsDefinition (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:1066:17)
at Parser.parseInputObjectTypeDefinition (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:1050:23)
at Parser.parseTypeSystemDefinition (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:714:23)
at Parser.parseDefinition (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:144:23)
at Parser.many (/Users/fveracoechea/Code/fveracoechea-website/node_modules/graphql/language/parser.js:1537:26)

    GraphQL Code Generator supports:
      - ES Modules and CommonJS exports (export as default or named export "schema")
      - Introspection JSON File
      - URL of GraphQL endpoint
      - Multiple files with type definitions (glob expression)
      - String in config file

    Try to use one of above options and run codegen again.
Error: Failed to load schema
    at loadSchema (/Users/fveracoechea/Code/fveracoechea-website/node_modules/@graphql-codegen/cli/bin.js:413:15)
    at async /Users/fveracoechea/Code/fveracoechea-website/node_modules/@graphql-codegen/cli/bin.js:796:55
    at async Task.task (/Users/fveracoechea/Code/fveracoechea-website/node_modules/@graphql-codegen/cli/bin.js:650:17)
Error: Failed to load schema
    at loadSchema (/Users/fveracoechea/Code/fveracoechea-website/node_modules/@graphql-codegen/cli/bin.js:413:15)
    at async /Users/fveracoechea/Code/fveracoechea-website/node_modules/@graphql-codegen/cli/bin.js:796:55
    at async Task.task (/Users/fveracoechea/Code/fveracoechea-website/node_modules/@graphql-codegen/cli/bin.js:650:17)

Something went wrong error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


rijkvanzanten commented 3 years ago

@franciscoemanuel Any idea where that "f" character comes from in the gql output?

fveracoechea commented 3 years ago

@rijkvanzanten well, I was looking at the gql schema and I found on the DirectusUsersFilter type that there are some attributes that start with a number 2

image