首页 > 解决方案 > 为 GitHub 获取 GraphQl __schema

问题描述

我正在尝试使用 get-graphql-schema 获取 GitHub 的架构,但出现错误:-

# 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)*

我对 Facebook 也有同样的看法,我不确定这是不是因为他们没有给出模式,或者它是否是get-graphql-schema的错误。

如何在 GraphiQL 资源管理器中以编程方式使用 GraphQl 通常获取架构?

标签: facebookgithubschemagraphql

解决方案


好的,这是一个以编程方式查询 __schema 条目的 GraphQL 脚本:-

  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


推荐阅读