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

Downloading scheme.json fails with specific command usage #844

Open
HAKASHUN opened this issue Dec 19, 2018 · 10 comments
Open

Downloading scheme.json fails with specific command usage #844

HAKASHUN opened this issue Dec 19, 2018 · 10 comments
Assignees
Labels
🐞 bug 🔨 cli related to the CLI itself

Comments

@HAKASHUN
Copy link

HAKASHUN commented Dec 19, 2018

Is it expected behavior to fail downloading scheme.json depending on the order of the options?

// Success
apollo schema:download --endpoint=<MyEndpoint> <MyOutputPath>/schema.json --header=<MyHeader>
  ✔ Loading Apollo Project
  ✔ Saving schema to <MyOutputPath>/schema.json

// Failed
apollo schema:download --endpoint=<MyEndpoint> --header=<MyHeader> <MyOutputPath>/schema.json
  ✔ Loading Apollo Project
  ✖ Saving schema to <MyOutputPath>/schema.json
    → Header name must be a valid HTTP Token [""]
TypeError: Header name must be a valid HTTP Token [""]
@morgan-edwards
Copy link

Same issue here

@robertpitt
Copy link

Same here

@pinkfloydsito
Copy link

same here

@BenBrostoff
Copy link

FWIW my solution to this was to pass the header flag outside of my npm script, which looked like the below:

"gql:schema": "apollo schema:download --endpoint=<endpoint> --header='Authorization: Bearer <token>' schema.json",

So instead of

yarn gql:schema

what worked for me was changing the script to remove --header='Authorization: Bearer <token>' and passing it through the terminal:

yarn gql:schema --header='Authorization: Bearer <token>'

@yongnicholaskim
Copy link

Somewhat related, trying to push our schema from a remote server to Apollo Engine using the CLI:

In my terminal, I've tried:

apollo service:push --header='Authorization: Bearer <token>'
apollo service:push --header="Authorization: Bearer <token>"
apollo service:push --header=Authorization: Bearer <token>

and every time the response I get is:

Error: Unable to validate user.

Is this API working for anybody out there? Any suggestions on what I may be doing wrong, and how to correct it? Or is this a bug?

FWIW, I'm supplying my service name and endpoint in my apollo.config.js file. Ultimately, I would like to move my validation credentials there also, so in my terminal I can just use:

apollo service:push

But there's no documentation on how to structure the apollo.config.js file for the header. This is what my apollo.config.js file looks like now:

module.exports = {
  service: {
    name: "<service name>",
    endpoint: {
      url: "<url>"
    },
    header: {
      Authorization: "Bearer <token>"
    }
  },
  engine: {
    apiKey: "<key>",
    schemaTag: "dev-test-proxy"
  }
};

At this point, ANY method for correctly supplying the header, either via the CLI in my terminal, or via my apollo.config.js would be nice.

@JakeDawkins JakeDawkins added 🐞 bug 🔨 cli related to the CLI itself labels Jul 10, 2019
@JakeDawkins JakeDawkins self-assigned this Jul 10, 2019
@kateile
Copy link

kateile commented Oct 28, 2019

same issue here.. I am just trying to download github to schema.json

apollo schema:download --endpoint=https://api.github.com/graphql --header='Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'  schema.json

anyone with solution?

@JakeDawkins
Copy link
Contributor

JakeDawkins commented Oct 28, 2019

@kateile Just put the output filename before the header flag. Oclif (the cli framework we build off of) has an issue with flag parsing when you allow multiple uses of the same flag.

So for example, if you want to provide multiple headers, you can either do

# this
apollo schema:download --endpoint=https://api.github.com/graphql schema.json --header="Authorization: Bearer xxxxxxxxxx" --header="MyHeader: 12345"

# or this
apollo schema:download --endpoint=https://api.github.com/graphql output.json --header="Authorization: Bearer xxxxxxx"  "MyHeader: 12345"

the second usage is definitely a bug, but since that bug exists right now, the CLI accidentally mistakes your schema.json arg as an additional header flag. So putting the header flag last fixes this for now.

@Relaxe111
Copy link

last suggestion worked for me :)

@qswitcher
Copy link

Just ran into this today with the latest version of apollo cli

@AnkitPatanaik
Copy link

@qswitcher likewise, just ran into this today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug 🔨 cli related to the CLI itself
Projects
None yet
Development

No branches or pull requests