Skip to main content

Use a connector for graphQL

Why using a connector for a GraphQL API

You can create your own API to support GraphQL using OpenAPI.

You won't have GraphQL feature like introspection, but you'll benefit all Meta API's feature like monitoring and authentication management.

That's our recommended way to use GraphQL inside Meta API.

How to add my API for GraphQL

You'll find below an OpenAPI template to create a generic API with one endpoint to use GraphQL.

Once you get this template, you'll have to edit it to change or add the following information:

  • Edit the title
  • Edit the target URL
  • Adjust (if needed) the path (by default /graphql)
  • Add a securitySchema according to your API (you have an example with an API Key inside the template)
  • Edit the global security object, according to your new security schema

OpenAPI Template

{
"openapi": "3.0.0",
"info": {
"title": "YOUR API",
"version": "1.0"
},
"servers": [
{
"url": "https://yourServer.com"
}
],
"paths": {
"/graphql": {
"post": {
"summary": "Get GraphQL",
"operationId": "post-graphql",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"description": "",
"type": "object",
"x-examples": {
"example-1": {
"data": {},
"errors": []
}
},
"properties": {
"data": {
"type": "object"
},
"errors": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"data",
"errors"
]
}
}
}
}
},
"tags": [
"graph"
],
"parameters": [
{
"schema": {
"type": "string",
"example": "{Post(id: \"XXX\") {votes {}}}"
},
"in": "query",
"name": "query",
"description": "Graph QL query. [See the official GraphQL documentation](https://graphql.org/learn/)."
}
],
"description": "",
"requestBody": {
"content": {
"application/json": {
"schema": {
"description": "",
"type": "object",
"x-examples": {
"example-1": {
"query": "...",
"operationName": "...",
"variables": {
"myVariable": "someValue"
}
}
},
"properties": {
"query": {
"type": "string",
"minLength": 1,
"description": "GraphQL query to be sent to the server"
},
"operationName": {
"type": "string",
"minLength": 1,
"description": "operationName is only required if multiple operations are present in the query."
},
"variables": {
"type": "object",
"description": "Query variables encoded has an JSON Object"
}
},
"required": [
"query"
]
},
"examples": {
"example-1": {
"value": {
"query": "{Post(id: 'XXX') {votes {}}}",
"operationName": "string",
"variables": {
"myVariable": "someValue"
}
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {},
"securitySchemes": {
"APIKey": {
"name": "api_key",
"type": "apiKey",
"in": "query"
}
}
},
"security": [
{
"APIKey": []
}
]
}