如何使用curl从GraphQL服务请求模式?

Dav*_*d H 6 graphql

我有一个curl 脚本(作为真实代码的代表),可以发布到我公司的GraphQL 端点并获取数据。运行良好。

看来还应该可以通过制作适当的请求来获取“模式”,但我还没有找到任何方法在 HTTP 级别上做到这一点。

如果可能的话,卷曲(数据)会是什么样子?

除了“查询”之外,还有其他请求可以用来收集其他信息吗?

pos*_*sum 13

您需要的主体非常涉及内省查询,但我认为您正在寻找类似的东西

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
                  }
                }
              }
            }
          }
        }
      }
    }"
}
Run Code Online (Sandbox Code Playgroud)

然后你可以做

curl -i -X POST http://localhost:8080/graphql -H "Content-Type: application/json" -d @introspection_query.json
Run Code Online (Sandbox Code Playgroud)

可耻地从 https://gist.github.com/martinheld/9fe32b7e2c8fd932599d36e921a2a825窃取