Skip to content

Reverse engineering the Shopify graphql API to generate server stubs.

License

Notifications You must be signed in to change notification settings

4thel00z/shopify-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shopify-graphql

Motivation

I want to reverse engineer the shopify graphql API.

What is the approach

Using this:

query IntrospectionQuery {
  __schema {
    queryType {
      name
    }
    mutationType {
      name
    }
    subscriptionType {
      name
    }
    types {
      ...FullType
    }
    directives {
      name
      description
      locations
      args {
        ...InputValue
      }
    }
  }
}

fragment FullType on __Type {
  kind
  name
  description
  fields(includeDeprecated: true) {
    name
    description
    args {
      ...InputValue
    }
    type {
      ...TypeRef
    }
    isDeprecated
    deprecationReason
  }
  inputFields {
    ...InputValue
  }
  interfaces {
    ...TypeRef
  }
  enumValues(includeDeprecated: true) {
    name
    description
    isDeprecated
    deprecationReason
  }
  possibleTypes {
    ...TypeRef
  }
}

fragment InputValue on __InputValue {
  name
  description
  type {
    ...TypeRef
  }
  defaultValue
}

fragment TypeRef on __Type {
  kind
  name
  ofType {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
              }
            }
          }
        }
      }
    }
  }
}

in the graphql explorer you can extract the schema.json. Find mine here. (I have remove the unnecessary parts that are returned by the explorer).

Using graphql-introspection-json you can easily generate the sdl from it using:

graphql-introspection-json-to-sdl schema.json > schema.graphql

Last step is to generate the stubs via gqlgen.

I spent the first half hours chasing a phantom bug which I assumed in gqlgen. However you have to remove the first alleged type inside the schema.graphql. It is sth. like QueryRoot or sth... If you don't throw it you will either:

  • build the glqgen stuff yourself and debug it
  • cry

Please don't cry.

crying cat

To spare you the cry etc. and because I am a nice person I will add the generated stuff here for reference.

License

This project is licensed under the GPL-3 license.

About

Reverse engineering the Shopify graphql API to generate server stubs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages