Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQLError: Syntax Error: Unexpected <EOF> when a file only contains commented out query/mutation #4426

Closed
capaj opened this issue Jul 24, 2020 · 7 comments
Assignees
Labels
dependencies waiting-for-release Fixed/resolved, and waiting for the next stable release

Comments

@capaj
Copy link
Contributor

capaj commented Jul 24, 2020

Describe the bug

/home/capaj/work-repos/4house/4house-fe-web/src/pages/pay/PayPage.gql
    GraphQLError: Syntax Error: Unexpected <EOF>.
        at syntaxError (/home/capaj/work-repos/4house/4house-fe-web/node_modules/g
raphql/error/syntaxError.js:15:10)
        at Parser.unexpected (/home/capaj/work-repos/4house/4house-fe-web/node_mod
ules/graphql/language/parser.js:1482:41)
        at Parser.parseDefinition (/home/capaj/work-repos/4house/4house-fe-web/nod
e_modules/graphql/language/parser.js:155:16)
        at Parser.many (/home/capaj/work-repos/4house/4house-fe-web/node_modules/g
raphql/language/parser.js:1537:26)
        at Parser.parseDocument (/home/capaj/work-repos/4house/4house-fe-web/node_
modules/graphql/language/parser.js:109:25)
        at Object.parse (/home/capaj/work-repos/4house/4house-fe-web/node_modules/
graphql/language/parser.js:36:17)
        at parseRawSDL (/home/capaj/work-repos/4house/4house-fe-web/node_modules/@
graphql-tools/load/index.cjs.js:507:41)
        at parseSource (/home/capaj/work-repos/4house/4house-fe-web/node_modules/@
graphql-tools/load/index.cjs.js:483:9)
        at /home/capaj/work-repos/4house/4house-fe-web/node_modules/@graphql-tools
/load/index.cjs.js:546:64
        at /home/capaj/work-repos/4house/4house-fe-web/node_modules/p-try/index.js
:4:10
        at new Promise (<anonymous>)
        at pTry (/home/capaj/work-repos/4house/4house-fe-web/node_modules/p-try/in
dex.js:3:37)
        at run (/home/capaj/work-repos/4house/4house-fe-web/node_modules/@graphql-
tools/load/node_modules/p-limit/index.js:24:18)
        at /home/capaj/work-repos/4house/4house-fe-web/node_modules/@graphql-tools
/load/node_modules/p-limit/index.js:46:18
    GraphQLError: Syntax Error: Unexpected <EOF>.
        at syntaxError (/home/capaj/work-repos/4house/4house-fe-web/node_modules/g
raphql/error/syntaxError.js:15:10)
        at Parser.unexpected (/home/capaj/work-repos/4house/4house-fe-web/node_mod
ules/graphql/language/parser.js:1482:41)
        at Parser.parseDefinition (/home/capaj/work-repos/4house/4house-fe-web/nod
e_modules/graphql/language/parser.js:155:16)
        at Parser.many (/home/capaj/work-repos/4house/4house-fe-web/node_modules/g
raphql/language/parser.js:1537:26)
        at Parser.parseDocument (/home/capaj/work-repos/4house/4house-fe-web/node_
modules/graphql/language/parser.js:109:25)
        at Object.parse (/home/capaj/work-repos/4house/4house-fe-web/node_modules/
graphql/language/parser.js:36:17)
        at parseRawSDL (/home/capaj/work-repos/4house/4house-fe-web/node_modules/@
graphql-tools/load/index.cjs.js:507:41)
        at parseSource (/home/capaj/work-repos/4house/4house-fe-web/node_modules/@
graphql-tools/load/index.cjs.js:483:9)
        at /home/capaj/work-repos/4house/4house-fe-web/node_modules/@graphql-tools
/load/index.cjs.js:546:64
        at /home/capaj/work-repos/4house/4house-fe-web/node_modules/p-try/index.js
:4:10
        at new Promise (<anonymous>)
        at pTry (/home/capaj/work-repos/4house/4house-fe-web/node_modules/p-try/in
dex.js:3:37)
        at run (/home/capaj/work-repos/4house/4house-fe-web/node_modules/@graphql-
tools/load/node_modules/p-limit/index.js:24:18)
        at /home/capaj/work-repos/4house/4house-fe-web/node_modules/@graphql-tools
/load/node_modules/p-limit/index.js:46:18

To Reproduce
Steps to reproduce the behavior:
just run codegen

  1. My GraphQL schema:
    doesn't matter

  2. My GraphQL operations:

# mutation payProduct($product: String!) {
#   createPaymentIntent(product: $product)
# }
  1. My codegen.yml config file:
    doesn't matter
    Expected behavior
    no error

Environment:

  • OS: ubutnut
  • @graphql-codegen/...: 1.17.4
  • NodeJS: 12

Additional context

commenting out a query/mutation should not cause codegen to fail. Maybe it could print a warning, but it should not fail.

@dotansimha
Copy link
Owner

Thank you for reporting this @capaj!
I guess we should try to check if it's possible to parse files and allow empty files in some cases.
@ardatan what do you think? is it something we can apply to the graphql-tools loaders?

@ardatan
Copy link
Collaborator

ardatan commented Jul 27, 2020

@capaj @dotansimha Instead of having an additional step on graphql-tools, I think graphql-js should return an empty DocumentNode in favor of this unreadable error. Do you agree?

@dotansimha
Copy link
Owner

@IvanGoncharov what do you think?
I think @ardatan is right, and graphql-js should parse empty strings (or, semi-empty strings, like in this example) as DocumentNode with zero definitions. Otherwise it makes is very hard for tools to detect this kind of input.

@danielrearden
Copy link
Contributor

@dotansimha @ardatan I think this is related to graphql/graphql-js#2241 and could probably done as part of that work. Even if we upstream this to graphql-js, though, it means anyone needing the fix will need to update to graphql@16 or whatever version it ends up being. In the meantime, would it be sufficient to just do something like this?

function isEmpty(source: string) {
  return source.replace(/^ *#.*/g, '').trim().length === 0
}

@dotansimha
Copy link
Owner

Latest graphql-tools is now using a wrapped method for the parse process, which allow empty files to be handled.
I think this should solve this issue as well.

@dotansimha
Copy link
Owner

Ok I can confirm that #4553 fixed this issue as well.
Will be available in a new release very soon.

@dotansimha dotansimha added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Aug 11, 2020
@dotansimha dotansimha self-assigned this Aug 11, 2020
@dotansimha
Copy link
Owner

Fixed in latest version of our plugins. Please make sure to update cli/core to latest (1.17.8), it will update @graphql-tools/ deps, and will fix that issue as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies waiting-for-release Fixed/resolved, and waiting for the next stable release
Projects
None yet
Development

No branches or pull requests

4 participants