Shopify GraphQL - no schema file exists even though it does

Todd_Trimakas
Shopify Partner
128 0 23

I'm trying to get started with Graphql and Shopify. I am getting the following error:

 

Client for API version 2020-01 does not exist because no schema file exists at `shopify_graphql_schemas/2020-01.json`. (ShopifyAPI::GraphQL::InvalidClient)

 


Even though I've run this rake task:

 

rake shopify_api:graphql:dump SHOP_DOMAIN="shipping-inventory-sync.myshopify.com" ACCESS_TOKEN="the_right_token" API_VERSION=2020-01

 

 

And I can see the file here: https://nimb.ws/ypDVAK and when I run

ShopifyAPI::GraphQL.schema_location

 

I get `#<Pathname:/home/shipping-new/db/shopify_graphql_schemas>`

 

I am only trying to do the following to get the shop name as a test:

 

sesh = ShopifyAPI::Session.new(domain: "shipping-inventory-sync.myshopify.com", token: 'xx', api_version: '2020-01')
ShopifyAPI::Base.activate_session(sesh)

client = ShopifyAPI::GraphQL.client

SHOP_NAME_QUERY = client.parse <<-'GRAPHQL'
{
  shop {
    name
  }
}
GRAPHQL

result = client.query(SHOP_NAME_QUERY)
pp result.data.shop.name

 

 

My Shopify Initializer config file also has the same `api_version` here:

config.api_version = "2021-01"

 

How can I download the schema in order to use GraphQL for Shopify?

ByteStand - Amazon to Shopify in one click
Replies 3 (3)
fangwz
Tourist
6 0 2

The whole schema of Shopify GraphQL could be fetched via a GraphQL request if you are familiar with GraphQL. It's sort of a self-described thing in GraphQL.

Here's a SDK on Github: https://github.com/YuanWenqing/shopify4j , which contains both GraphQL schemas of Admin GraphQL and Storefront GraphQL.

GraphQL queries to request the schema can also be found there. You may find the similar query by hacking the request when loading a Shopify GraphQL Explorer.

May it help!

Leocxy88
Shopify Partner
4 0 3

If you know python. You can grab the GraphQL Schema with sgqlc.

 

python3 -m sgqlc.introspection \
     --exclude-deprecated \
     --exclude-description \
     -H "X-Shopify-Access-Token: ACCESS_TOKEN" \
     https://YOUR-STORE.myshopify.com/admin/api/2021-04/graphql.json \
     shopify_schema.json

 

If you link you can convert the shopify_schema.json to a Python schema class

 

sgqlc-codegen schema shopify_schema.json shopify_schema.py

 

mojtaba-hengam
New Member
1 0 0

Hi,

Is there any tool for converting admin-schema@2021-01.json to the graphql SDL format?

I used some tools like json-schema-to-graphql-types, but it didn't work.

Thanks in advance