marjory-logo

GraphQL

Table of Contents


Contexts

token

Type Description isCrypt
string The authentication token. If it is a Bearer token, please write "Bearer ". true

baseUrl

Type Description isCrypt
string GraphQL API base url false

Actions

Send Request

Send Request

Documentation

Perform a query

Here is an example with the Star Wars GraphQL API

First of all, configure the credentials as :

 "baseUrl": "https://swapi-graphql.netlify.app/.netlify/functions/index/"

The Action inputs should be :

return {
     "path": "star-wars-swapi",
     "content": `query Query { 
          allFilms {
               films {
                    title
               }
          }
     }`
}

When executing this action, the output will be :

{
    "allFilms": {
        "films": [
            {
                "title": "A New Hope"
            },
            {
                "title": "The Empire Strikes Back"
            },
            {
                "title": "Return of the Jedi"
            },
            {
                "title": "The Phantom Menace"
            },
            {
                "title": "Attack of the Clones"
            },
            {
                "title": "Revenge of the Sith"
            }
        ]
    }
}

Perform a Mutation with variables

Here is an example with the Apollo Sandbox API

First of all, configure the credentials as :

 "baseUrl": "https://apollo-fullstack-tutorial.herokuapp.com/graphql/Login"

The Action inputs should be :

return {
    "path": "Login", 
    "content":  `mutation Login($email: String) { 
        login(email: $email){ 
            email 
        } 
    } `,
    "variables": {
         "email": "me@example.com" 
    }
}

The email variable will have me@example.com value when executing the query.

Generate dynamic requests

In your Marjory script Monaco in Editor, you can declare local variable, and use t in your prescript :

var field = 'total';

return {
    "path": "<api-path>",
    "content":  `query {
         versionCollection {
            ${field} 
        }
    }`
}

Inputs

{
  "path": "string", /*The endpoint path that will be concatenated with the baseUrl, to reach the desired function*/
  "content": "string", /*GraphQL request in a string (can be a mutation or a query)(required)*/
  "variables": { /*GraphQL request variables as JSON object*/
    "any": "string",
  }
}

Outputs

Http Code 200
{
  "data": {}
}
Http Code 500
{
  "message": "Error"
}
Version(s)
1.1.1