Skip to content

Instantly share code, notes, and snippets.

@KendraTang
Created November 6, 2020 03:36
Show Gist options
  • Save KendraTang/92bc1fbe7c545f4125805669c7b27bba to your computer and use it in GitHub Desktop.
Save KendraTang/92bc1fbe7c545f4125805669c7b27bba to your computer and use it in GitHub Desktop.

Steps

  • ./curl > result.json

  • npm install

  • node index.js > out.graphql

curl 'https://shopify.dev/admin-graphql-proxy' \
-H 'authority: shopify.dev' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36' \
-H 'content-type: application/json' \
-H 'accept: */*' \
-H 'origin: https://shopify.dev' \
-H 'sec-fetch-site: same-origin' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-dest: empty' \
-H 'referer: https://shopify.dev/graphiql/admin-graphiql' \
-H 'accept-language: zh-TW,zh;q=0.9' \
--data-binary '{"graphQLParams":{"query":"\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n ","operationName":"IntrospectionQuery"},"version":"2020-10"}' \
--compressed
const { buildClientSchema, printSchema } = require("graphql");
const fs = require("fs");
const introspectionSchemaResult = JSON.parse(fs.readFileSync("result.json")).data;
const graphqlSchemaObj = buildClientSchema(introspectionSchemaResult);
console.log(printSchema(graphqlSchemaObj));
{
"name": "clone-schema",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"graphql": "^15.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment