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

Syntax Error: Cannot parse the unexpected character "/". #2

Closed
gex opened this issue Feb 1, 2018 · 13 comments
Closed

Syntax Error: Cannot parse the unexpected character "/". #2

gex opened this issue Feb 1, 2018 · 13 comments

Comments

@gex
Copy link

gex commented Feb 1, 2018

i get this syntax error when using the generate-fragments command:

$ API_URL=foo AUTH_TOKEN=bar graphql generate-fragments -p default -g js -o baz --save
✖ Generating fragments for project default...
Syntax Error: Cannot parse the unexpected character "/".

my .graphqlconfig:

{
  "schemaPath": "schema.json",
  "extensions": {
    "endpoints": {
      "default": {
        "url": "${env:API_URL}",
        "headers": {
          "Authorization": "Bearer ${env:AUTH_TOKEN}"
        }
      }
    }
  }
}

i've successfully saved the schema file (with graphql get-schema) so the url and the token are valid.

from my package.json:

"graphql-cli": "^2.13.0",
"graphql-cli-generate-fragments": "^1.1.0",
@develomark
Copy link
Owner

develomark commented Feb 10, 2018

Hi @gex super apologies for the delay - I've been on holiday.

In your .graphqlconfig you have a json file. schemaPath": "schema.json,- This should be a graphql schema.

Did you run graphql init?

If you follow the steps laid out in "see it in action" from: https://github.com/graphql-cli/graphql-cli you should be able to run graphql get-schema afterwards and then graphql generate-fragments

@develomark
Copy link
Owner

@gex How did you go?

@gex
Copy link
Author

gex commented Feb 12, 2018

@develomark yep i was able to save the schema with graphql get-schema as i mentioned it in my previous comment:

i've successfully saved the schema file (with graphql get-schema) so the url and the token are valid.

after i successfully run graphql init and graphql get-schema i got the syntax error with graphql generate-fragments :(

@develomark
Copy link
Owner

develomark commented Feb 14, 2018

Can you share your .graphqlconfig? It shows schemaPath": "schema.json, as opposed to schemaPath": "schema.graphql

@develomark
Copy link
Owner

@gex Can you share with me your schema?

@gex
Copy link
Author

gex commented Feb 14, 2018

they added json output to graphql-cli and i thought schema.json would be more straightforward than storing json in a schema.graphql file. :)

i'm not allowed to post my schema publicly but if it helps i can share it with you.

@develomark
Copy link
Owner

I didn't know that - seems to be undocumented!

I wouldn't suggest that it is more straightforward. All the tooling pulls in .graphql files. graphql-tag, graphql-import etc. etc.

What is the usecase for json over graphql for the schema?

@gex
Copy link
Author

gex commented Feb 14, 2018

to be honest i don't remember exactly why i switched to json. i tried to setup a lot of things together. i'm using apollo, v2 needs fragment matching so i installed graphql-cli with your plugin then i thought it would also be nice to validate all of my queries and mutations with eslint-plugin-graphql but i use eslint-plugin-prettier and those two are not compatible yet (eslint-plugin-graphql #109 and eslint-plugin-prettier #81). somewhere in this process i switched to json. :)

i switch back to graphql extension and try to get the fragments with that setup and get back to you with the results!

@develomark
Copy link
Owner

Under the hood this is passing SDL (the schema) via importSchema() and passSDL() fromgraphql-import - it doesn't have a method to pass JSON.

I'll update the error message for this so it now throws a more informative error message.

Thanks for the spot @gex

@develomark
Copy link
Owner

OK that's done.

Please update to the latest.

@gex
Copy link
Author

gex commented Feb 14, 2018

thank you for your time and help!

@gex
Copy link
Author

gex commented Feb 14, 2018

okay, now i remember why i switched to json:

  1. eslint-plugin-graphql needs the schema in json format
  2. apollo documentation recommends "setting up a build step that extracts the necessary information from the schema into a JSON file, where it can be imported from when constructing the fragment matcher" and i don't know why but i supposed this plugin will help me to extract that data from the schema but i was wrong :D

@develomark
Copy link
Owner

@gex Hey no problem.

FYI you don't need to have the schema in json for eslint-plugin-graphql I've got that working with SDL. It automatically picks it up from .graphqlconfig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants