skip to Main Content

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?

3

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. Try changing the Content-Type to application/json.

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

    Login or Signup to reply.
  3. 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!
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search