0

Has anyone had luck with placing a GraphQL custom type argument as a Postman or Graphql variable? I'm kinda spinning in circles right now, I hope a fresh pair of eyes could point me in the right direction. What I'm trying to do is to send a mutation request using Postman. The problem I'm having is that the method I'm calling is taking a custom type as an argument. Placing the content of that variable as GraphQL variable or Postman variable is giving me a headache. I can't embedd pictures yet, so here are the links (they are safe).

Schema

This custom type is a JSON-like structure, consisting of two enums and a set of primitive types (strings, ints...). I can screenshot the entire thing but basically that's it: two enums followed by strings, ints... Custom type definition

What I've tried so far:

  • Simply hardcoding the request in Postman works but I wish to send multiple requests with varying data
  • Placing it in a GraphQL variable results in error message

{ "errors": [ { "message": "Bad request - invalid request body.", "locations": [] } ], "data": null }

  • Placing the custom type content as a Postman environment variable works, but I'm getting a syntax error (although the request passes...). Request body is below. Hardcoding it and using a Postman variable produces the same request body, apart from the syntax error.
query: "mutation {
  createApplication(request: { 
    applicationKind: NEW_ISSUANCE,
    documentKind: REGULAR_PASSPORT,
    personalData: {
        timestamp: null,
        firstname: "NAME",
        lastname: "LASTNAME",
        middlename: "MIDDLENAME",
        dateOfBirth: "2011-09-28",
        citizenshipCountryCode: "USA",
        gender: MALE,
        personalNumber: "3344",
        placeOfBirth: "CHICAGO",
        municipalityOfBirth: "SOUTH",
        countryCodeOfBirth: "USA"},
    addressData:{
        street: "WEST",
        municipality: "EAST",
        place: "CHICAGO",
          country: {
            code: "USA",
            name: null
          },
        entrance: "б",
        flat: "13",
        number: "35"}
}) 
    {
    __typename
    ... on AsyncTaskStatus {
      taskID
      state
      payload {
        ... on ApplicationUpdated {
          applicationID
          applicationNumber
          __typename
        }
        __typename
      }
      __typename
    }
    ... on Error {
      ...errorData
      __typename
    }
  }
}

fragment errorData on Error {
  __typename
  code
  message
}"

Postman variable with a squiggly line

I'm spinning in circles right now. Has anyone had any luck with Postman requests of this kind? I can post more info, screenshots...just let me know. I'll be watching this topic closely and provide feedback.

Thank you for your time.

1 Answers1

0

enter image description here

please add a the variable in variable section as :

{
"request": {{request}}
}

and then refer this in your query as

$request
PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Hi. I tried that. Doint that results in ` "errors": [ { "message": "Bad request - invalid request body.", "locations": [] } ], "data": null` Entire request is a variable starting with { and finishing with } – Nikola Pepic Sep 29 '21 at 10:29
  • Try json data raw body type instead then – PDHide Sep 29 '21 at 11:24
  • 1
    I had to change the Content-type in the header to application/graphql and body type to raw and it works! Thanks. Why won't it resolve the GraphQL variable in the GraphQL body type is beyond me... – Nikola Pepic Sep 29 '21 at 12:14