I have a curl script (as a standin for real code) that can POST to my company's GraphQL endoint and get data. It's working fine.
It appears that it should also be possible to get the "schema" by crafting the appropriate request, but I have not found any way to do that at a HTTP level.
If it is possible, what would the curl look like (the data)?
Are there other requests other than "query" that I can use to gleen other information?
The body you need is pretty involved for an introspection query, but I think you're looking for something like this
introspection_query.json:
{ 
  "query": "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
                  }
                }
              }
            }
          }
        }
      }
    }"
}
and then you can do
curl -i -X POST http://localhost:8080/graphql -H "Content-Type: application/json" -d @introspection_query.json
Shamefully stolen from https://gist.github.com/martinheld/9fe32b7e2c8fd932599d36e921a2a825
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With