Get GraphQL whole schema query

后端 未结 10 1095
花落未央
花落未央 2020-12-22 23:23

I want to get the schema from the server. I can get all entities with the types but I\'m unable to get the properties.

Getting all types:

query {
  _         


        
相关标签:
10条回答
  • 2020-12-23 00:20

    You can use IntelliJ plugin JS GraphQL then IDEA will ask you create two files "graphql.config.json" and "graphql.schema.json"

    Then you can edit "graphql.config.json" to point to your local or remote GraphQL server:

    "schema": {
    "README_request" : "To request the schema from a url instead, remove the 'file' JSON property above (and optionally delete the default graphql.schema.json file).",
    "request": {
      "url" : "http://localhost:4000",
      "method" : "POST",
      "README_postIntrospectionQuery" : "Whether to POST an introspectionQuery to the url. If the url always returns the schema JSON, set to false and consider using GET",
      "postIntrospectionQuery" : true,
      "README_options" : "See the 'Options' section at https://github.com/then/then-request",
      "options" : {
        "headers": {
          "user-agent" : "JS GraphQL"
        }
      }
    }
    

    After that IDEA plugin will auto load schema from GraphQL server and show the schema json in the console like this:

    Loaded schema from 'http://localhost:4000': {"data":{"__schema":{"queryType":{"name":"Query"},"mutationType":{"name":"Mutation"},"subscriptionType":null,"types":[{"kind":"OBJECT","name":"Query","description":"","fields":[{"name":"launche
    
    0 讨论(0)
  • 2020-12-23 00:21

    You can use the Hasura's graphqurl utility

    npm install -g graphqurl
    
    gq <endpoint> --introspect > schema.graphql
    
    # or if you want it in json
    gq <endpoint> --introspect --format json > schema.json
    

    Full documentation: https://github.com/hasura/graphqurl

    0 讨论(0)
  • 2020-12-23 00:23

    Update

    Using graphql-cli is now the recommended workflow to get and update your schema.

    The following commands will get you started:

    # install via NPM
    npm install -g graphql-cli
    
    # Setup your .graphqlconfig file (configure endpoints + schema path)
    graphql init
    
    # Download the schema from the server
    graphql get-schema
    

    You can even listen for schema changes and continuously update your schema by running:

    graphql get-schema --watch
    

    In case you just want to download the GraphQL schema, use the following approach:

    The easiest way to get a GraphQL schema is using the CLI tool get-graphql-schema.

    You can install it via NPM:

    npm install -g get-graphql-schema
    

    There are two ways to get your schema. 1) GraphQL IDL format or 2) JSON introspection query format.

    GraphQL IDL format

    get-graphql-schema ENDPOINT_URL > schema.graphql
    

    JSON introspection format

    get-graphql-schema ENDPOINT_URL --json > schema.json
    

    or

    get-graphql-schema ENDPOINT_URL -j > schema.json
    

    For more information you can refer to the following tutorial: How to download the GraphQL IDL Schema

    0 讨论(0)
  • 2020-12-23 00:24

    You can download a remote GraphQL server's schema with the following command. When the command succeeds, you should see a new file named schema.json in the current working directory.

    ~$ npx apollo-cli download-schema $GRAPHQL_URL --output schema.json

    0 讨论(0)
提交回复
热议问题