github.com/r0busta/go-shopify-graphql-model@v0.0.4/schema-fetcher.js (about)

     1  const path = require("path")
     2  const fs = require("fs")
     3  const fetch = require("node-fetch")
     4  const { getIntrospectionQuery, printSchema, buildClientSchema } = require("graphql")
     5  
     6  async function main() {
     7      const introspectionQuery = getIntrospectionQuery()
     8  
     9      const response = await fetch(`https://${process.env.STORE}.myshopify.com/admin/api/2021-04/graphql.json`, {
    10          method: "POST",
    11          headers: {
    12              "Content-Type": "application/json",
    13              "X-Shopify-Access-Token": process.env.PASSWORD,
    14          },
    15          body: JSON.stringify({ query: introspectionQuery }),
    16      })
    17  
    18      const { data } = await response.json()
    19  
    20      const schema = buildClientSchema(data)
    21  
    22      const outputFile = path.join(__dirname, "./result.graphql")
    23  
    24      await fs.promises.writeFile(outputFile, printSchema(schema))
    25  }
    26  
    27  main()