magic.77
magic.77

Reputation: 917

Shopify GraphQL Get Schema from Server

I am using graphql-js-schema-fetch to fetch Shopify schema, but it throws an error and I do not know how to fix it.

Using CLI:

graphql-js-schema-fetch https://myspati-com.myshopify.com/api/graphql --header "Content-Type: application/graphql" --header "X-Shopify-Storefront-Access-Token: <acces-token>"

This is the error:

{
    "errors": [{
        "message": "Parse error on \"query\" (STRING) at [1, 2]",
        "locations": [{
            "line": 1,
            "column": 2
        }]
    }]
}

Anyone with experience here?

Upvotes: 3

Views: 6941

Answers (4)

Patrick
Patrick

Reputation: 11

Working solution:

graphql-js-schema-fetch https://{SUBDOMAIN}.myshopify.com/admin/api/2025-01/graphql.json --header "X-Shopify-Access-Token:{ACCESS_TOKEN}"

Upvotes: 1

Hem&#227; Vidal
Hem&#227; Vidal

Reputation: 1872

The only solution that worked for me was:

apollo service:download types/download.json --endpoint=https://{your-shop}.myshopify.com/admin/api/2022-04/graphql.json --header="X-Shopify-Access-Token: <admin-access-token>"

PS: Change the 2022-04 to the latest API version.

If you want the download file into a SDL format instead of JSON use this approach:

apollo client:download-schema types/download.graphql --endpoint=https://{your-shop}.myshopify.com/admin/api/2022-04/graphql.json --header="X-Shopify-Access-Token: <admin-access-token>"

Apollo client will conside the output as a SDL format:

"""
Returns unfulfilled line items grouped by their fulfillment service. Each draft fulfillment contains additional information, such as whether the fulfillment requires shipping and whether a shipping label can be printed for it.
"""
type DraftFulfillment {
  """Whether a label can be purchased."""
  allowLabelPurchase: Boolean!

  """
  The line items (which might correspond to a variant) that are part of this draft fulfillment.
  """
  lineItems: [LineItem!]!

  """Whether a fulfillment requires shipping."""
  requiresShipping: Boolean!

  """The service responsible for fulfilling the fulfillment."""
  service: FulfillmentService!
}

Upvotes: 1

magic.77
magic.77

Reputation: 917

I had to remove "Content-Type" and Access-Token and replace it with the Shopifys credentials. Now it works for me.

graphql-js-schema-fetch --url 'https://graphql.myshopify.com/api/graphql' --header 'Authorization: Basic MzUxYzEyMjAxN2QwZjJhOTU3ZDMyYWU3MjhhZDc0OWM=' | jq '.' > shopify-schema.json

Upvotes: 0

tonyyin
tonyyin

Reputation: 331

Try changing the Content-Type to application/json.

This works for me despite all the docs saying to use application/graphql

Upvotes: 20

Related Questions