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

fetching a remote schema throws 400 errors #573

Closed
opsinghis opened this issue May 25, 2021 · 9 comments
Closed

fetching a remote schema throws 400 errors #573

opsinghis opened this issue May 25, 2021 · 9 comments
Labels
Milestone

Comments

@opsinghis
Copy link

Description

I am trying to get a remote schema using command below. This schema is from commercetools.

rover subgraph introspect https://api.europe-west1.gcp.commercetools.com/XXXXXX/graphql --header "Authorization:Bearer XXXXXXXXXXXXXXXXXX"

I am getting the following response

error[E004]: HTTP status client error (400 Bad Request) for url (https://api.europe.west1.gcp.commercetools.com/XXXXXXXX/graphql)
This error was unexpected! Please submit an issue with any relevant details about what you were trying to do: https://github.com/apollographql/rover/issues/new/choose

I use another cli utility from “get-graphql-schema” and this works perfectly fine

Steps to reproduce

Commercetools is a headless commerce platform. I am trying to configure federation across commercetools and contentful both of them support graphql.

In order to setup subgraphs as described in the documentation
https://www.apollographql.com/docs/federation/quickstart/

I am configuring the application to get the commercetools schema, by replicating the advised command

rover subgraph introspect https://rover.apollo.dev/quickstart/products/graphql

Expected result

I should get access to graphql schema.

Actual result

error[E004]: HTTP status client error (400 Bad Request) for url (https://api.europe.west1.gcp.commercetools.com/XXXXXXXX/graphql)
This error was unexpected! Please submit an issue with any relevant details about what you were trying to do: https://github.com/apollographql/rover/issues/new/choose

Environment

Run rover info and paste the results here

If you can't run rover info for some reason, please provide as much of the following info as possible:

  • Operating system and version: Mac OS
  • Shell (bash/zsh/powershell):
  • Version of Rover (rover --help):
  • Apollo Studio Plan: [free/team/enterprise/none]
  • Installation method: [curl/npm/npx/build from source]
@opsinghis opsinghis added bug 🐞 triage issues and PRs that need to be triaged labels May 25, 2021
@EverlastingBugstopper
Copy link
Contributor

Hi @opsinghis - thanks for the report. rover subgraph introspect is using a separate GraphQL introspection query that will not work unless the graph you are trying to introspect is a federated subgraph.

The command you're looking for here is rover graph introspect, which will work similarly to get-graphql-schema

@opsinghis
Copy link
Author

Hence in this case - i would need to download the schema using rover graph introspect, and manually convert them to a specification of sub graphs and then imprort them back as subgraphs.

I would assume most third party remote graphs are unlikely to adhere to federation specification - hence the only option left for us is to manually convert them.

Om

@EverlastingBugstopper
Copy link
Contributor

Yup! That's exactly right. There are docs here that might be able to help with this conversion process.

@EverlastingBugstopper
Copy link
Contributor

EverlastingBugstopper commented May 27, 2021

This should be fixed with a better error message in v0.1.5! Please feel free to reopen this issue, or create a new issue if you are still having issues.

@gevuong
Copy link

gevuong commented May 5, 2022

Hi I know this issue is closed but I'm encountering a similar issue that returns the same 400 error.
The GraphQL query works in postman with the apollo server URL and API key in the header.
The graph is not federated, and is a monolith, so therefore I'm using rover graph instead of rover subgraph.

Now, I would like to fetch the GraphQL server's schema via introspection and write it to a temp.gql file.

rover graph introspect $SERVICE_ENDPOINT -H=apikey:$APIKEY > temp.gql

but it returns the following:

error[E004]: HTTP status client error (400 Bad Request) for url (https://xxx/xxx/graphql)
        This error was unexpected! Please submit an issue with any relevant details about what you were trying to do: https://github.com/apollographql/rover/issues/new/choose

I tested the command against a locally running apollo server (w/out the API key) and it works. I also made sure the env variables are populated with the correct values via echo command.

Any idea what the cause of this is?
I wouldn't need an APOLLO_KEY variable for introspection, would I?

@EverlastingBugstopper
Copy link
Contributor

That's strange @gevuong - what version of Rover? Also, maybe you could get some more information here if you run the command with --log debug

@gevuong
Copy link

gevuong commented May 6, 2022

Hi @EverlastingBugstopper,

❯ rover -V
Rover 0.6.0

I ran with --log debug like so:
rover graph introspect https://xxx.com/xxx/graphql -H apikey:xxx --log debug

According to logs, it looks like a connection was made to the server, headers were parsed, and the body of the request was received. But afterward, it throws a 400 😕 . And yes, the expected API key name is apikey.

  DEBUG reqwest::connect: starting new connection: https://xxx.com/
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/reqwest-0.11.10/src/connect.rs:560

  DEBUG hyper::client::connect::dns: resolving host="xxx.com"
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/client/connect/dns.rs:122

  DEBUG hyper::client::connect::http: connecting to xxx
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/client/connect/http.rs:537

  DEBUG hyper::client::connect::http: connecting to xxx
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/client/connect/http.rs:537

  DEBUG hyper::client::connect::http: connected to xxx
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/client/connect/http.rs:540

  DEBUG hyper::client::connect::http: connected to xxx
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/client/connect/http.rs:540
  DEBUG hyper::proto::h1::io: flushed 1706 bytes
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/proto/h1/io.rs:334

  DEBUG hyper::proto::h1::io: flushed 569 bytes
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/proto/h1/io.rs:334

  DEBUG hyper::proto::h1::io: parsed 10 headers
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/proto/h1/io.rs:205

  DEBUG hyper::proto::h1::conn: incoming body is content-length (1576 bytes)
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/proto/h1/conn.rs:217

  DEBUG hyper::proto::h1::conn: incoming body completed
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/proto/h1/conn.rs:293

  DEBUG hyper::client::pool: pooling idle connection for ("https", xxx.com)
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.18/src/client/pool.rs:376

  DEBUG reqwest::async_impl::client: response '400 Bad Request' for https://xxx.com/xxx/graphql
    at /Users/distiller/.cargo/registry/src/github.com-1ecc6299db9ec823/reqwest-0.11.10/src/async_impl/client.rs:1917
    ```

@EverlastingBugstopper
Copy link
Contributor

That's so strange! OK I'm going to recommend that you try running the query that Rover is running here as a cURL request to see if the body of the response gives you any meaningful information here.

curl -X POST https://my-api.com/graphql -H apikey:myapikey -H content-type:application/json -H user-agent: rover/0.6.0 -d '{"variables":null,"query":"query GraphIntrospectQuery {\n  __schema {\n    queryType {\n      name\n    }\n    mutationType {\n      name\n    }\n    subscriptionType {\n      name\n    }\n    types {\n      ...FullType\n    }\n    directives {\n      name\n      description\n      locations\n      args {\n        ...InputValue\n      }\n    }\n  }\n}\n\nfragment FullType on __Type {\n  kind\n  name\n  description\n  fields(includeDeprecated: true) {\n    name\n    description\n    args {\n      ...InputValue\n    }\n    type {\n      ...TypeRef\n    }\n    isDeprecated\n    deprecationReason\n  }\n  inputFields {\n    ...InputValue\n  }\n  interfaces {\n    ...TypeRef\n  }\n  enumValues(includeDeprecated: true) {\n    name\n    description\n    isDeprecated\n    deprecationReason\n  }\n  possibleTypes {\n    ...TypeRef\n  }\n}\n\nfragment InputValue on __InputValue {\n  name\n  description\n  type {\n    ...TypeRef\n  }\n  defaultValue\n}\n\nfragment TypeRef on __Type {\n  kind\n  name\n  ofType {\n    kind\n    name\n    ofType {\n      kind\n      name\n      ofType {\n        kind\n        name\n        ofType {\n          kind\n          name\n          ofType {\n            kind\n            name\n            ofType {\n              kind\n              name\n              ofType {\n                kind\n                name\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}","operationName":"GraphIntrospectQuery"}'

@gevuong
Copy link

gevuong commented May 9, 2022

Alrighty, so with the help of your curl command, the returned error stated introspection needed to be set to true.
I then added introspection: true and now it works!

With that being said, based on Apollo Server docs, under the introspection schema option, The default value is true, unless the NODE_ENV environment variable is set to production. I'm not 100% sure, but I don't think the NODE_ENV is set to production since the app I was attempting to introspect was deployed to a dev environment.

It is important to note, however, that I am using GraphQLModule from @nestjs/graphql.

Anyway, thanks for all your help, @EverlastingBugstopper!

@abernix abernix removed the triage issues and PRs that need to be triaged label Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants