How to send graphql query by postman?

前端 未结 14 657
情歌与酒
情歌与酒 2020-11-29 16:19

I use

POST type
URL http://######/graphql
Body: 
query: \"query: \"{\'noteTypes\':  {\'name\', \'label\', \'labelColor\', \'groupName\', \'groupLabel\', \'i         


        
相关标签:
14条回答
  • 2020-11-29 16:56

    There's a simple way to do it. Use a pre-request script to stringify the payload (source).

    Step 1.

    In the body of the request put a placeholder for the payload.

    {
        "query":{{query}}
    }
    

    Step 2.

    Create the payload in the pre-request script and store it in an environment variable.

    postman.setEnvironmentVariable("query", JSON.stringify(
    `
    {
      search(query: "test", type: ISSUE, first: 10) {
        issueCount
        edges {
          node {
            ... on Issue {
              title
              id
              state
              closed
              repository {
                name
              }
            }
          }
        }
      }
    }
    `
    ));
    

    That's it.

    0 讨论(0)
  • 2020-11-29 16:56

    Postman has recently launched its out of box support for GraphQL: https://blog.getpostman.com/2019/06/18/postman-v7-2-supports-graphql/

    Below is the screenshot of testing GraphQL locally:

    Note: Running GraphQL locally using spring-boot https://www.baeldung.com/spring-graphql

    0 讨论(0)
  • 2020-11-29 16:57

    Postman just released inbuilt GraphQL support in version 7.2.

    This version supports

    • Sending GraphQL queries in request body as POST requests
    • Support for GraphQL variables
    • Creating APIs in Postman with GraphQL schema type
    • Query autocompletion integrated with user defined GraphQL schemas

    Please give it a try and give us your feedback on the tracking thread on our community forum

    0 讨论(0)
  • 2020-11-29 16:58

    You don't need INSOMNIA in case the GraphQL server responds to Content-type: application/graphql or postman.setEnvironmentVariable,

    Just do it:

    In Headers tab: Content-Type: application/graphql

    In Body tab, "raw" selected, put your query

    0 讨论(0)
  • 2020-11-29 17:02

    By adding header we can run graphql query in the postman

    Content-type: application/graphql

    0 讨论(0)
  • 2020-11-29 17:03

    UPDATE 8-2019 - I know this is old, but regarding POSTMAN, if you haven't figured it out already, they do have a graphql (beta) option for posting body. There is no need to add any additional headers.

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