简体   繁体   中英

Getting GraphQl __schema for GitHub

I am trying to get the schema for GitHub using get-graphql-schema but am getting an error :-

# npm install -g get-graphql-schema
# get-graphql-schema https://api.github.com/graphql

*TypeError: Cannot read property '__schema' of undefined
  at Object.buildClientSchema 
  (C:\Users\Aaron\AppData\Roaming\npm\node_modules\get-graphql-schema\node_modules\graphql\utilities\buildClientSchema.js:48:43)*

I get the same for Facebook I am not sure if this is because they don't give the schemas or whether its an error with get-graphql-schema .

How do I programmatically get the schema using GraphQl normally in the GraphiQL explorer ?

Okay heres a GraphQL script that programmatically queries the __schema entry :-

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

  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
        }
      }
    }
  }

https://gist.github.com/AaronNGray/c873c093f7015389cd7358d7270e1e1e

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM