【问题标题】:Getting GraphQl __schema for GitHub为 GitHub 获取 GraphQl __schema
【发布时间】:2018-11-14 08:58:42
【问题描述】:

我正在尝试使用 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 以编程方式获取架构?

【问题讨论】:

    标签: facebook github schema graphql


    【解决方案1】:

    好的,这是一个以编程方式查询 __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

    【讨论】:

      猜你喜欢
      • 2020-01-12
      • 1970-01-01
      • 2018-02-25
      • 2021-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      相关资源
      最近更新 更多