apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 467 forks source link

Downloading scheme.json fails with specific command usage #844

Open HAKASHUN opened 5 years ago

HAKASHUN commented 5 years ago

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 commented 5 years ago

Same issue here

robertpitt commented 5 years ago

Same here

pinkfloydsito commented 5 years ago

same here

BenBrostoff commented 5 years ago

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 commented 5 years ago

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.

kateile commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

last suggestion worked for me :)

qswitcher commented 4 years ago

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

AnkitPatanaik commented 3 years ago

@qswitcher likewise, just ran into this today