Shopify GraphQL 从服务器获取模式

3
我将使用"graphql-js-schema-fetch"来获取Shopify的模式,但它抛出了一个错误,我不知道该如何解决。
使用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>"

这是错误信息:

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

有没有相关经验的人?

3个回答

20
尝试将 Content-Type 改为 application/json。尽管所有文档都建议使用 application/graphql,但这种方式对我有效。

我在使用Postman时遇到了同样的错误,通过传递application/json解决了问题,但这可能是客户端的“问题”,我正在使用的PHP API发送变异的json和查询的graphql,两者都可以正常工作。 - Alex

1

对我有效的唯一解决方案是:

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:请将2022-04更改为最新的API版本。
如果您想将下载文件转换为SDL格式而不是JSON,请使用以下方法:
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客户端将把输出视为SDL格式:
"""
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!
}

你是一个传奇!最新的API版本已更改为2023-04 - l000p

0

我不得不删除“Content-Type”和“Access-Token”,并用Shopify的凭据替换它。现在它对我起作用了。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接