簡體   English   中英

Shopify GraphQL 從服務器獲取架構

[英]Shopify GraphQL Get Schema from Server

我正在使用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
        }]
    }]
}

有沒有人在這里有經驗?

嘗試將Content-Type更改為application/json

盡管所有文檔都說使用application/graphql對我application/graphql

我不得不刪除“Content-Type”和Access-Token,並將其替換為Shopifys憑據。 現在它對我有用。

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

唯一對我有用的解決方案是:

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 客戶端會將 output 視為 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!
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM