# README

GraphQL

The graphql service type accepts GraphQL request and applies policies and validates against the schema.

The service settings and available input for the request are as follows:

The available service settings are as follows:

NameTypeDescription
modesettingmode 'a': validate request against GraphQL schema and maximum allowed query depth. mode 'b': Throttle requests based on server time
limitsettingLimit specified in the format maxLimit-fillLimit-fillRate in milli seconds. Example: 1000-200-2000 indicates - maximum server time is set to 1000ms and client gains 200ms of server time per 2000ms

The available input for the request are as follows:

NameTypeDescription
queryinputGraphQL request string
schemaFileinputGraphQL schema file path
maxQueryDepthinputMaximum allowed GraphQL query depth
tokenstringToken for which rate limit has to be applied
operationstringAn operation to perform: startconsume - start consuming the server time. stopconsume - stop consuming server time

The available response outputs are as follows:

NameTypeDescription
validbooleantrue if the GraphQL query is valid
errorbooleantrue if any error occured while inspecting the GraphQL query
errorMessagestringThe error message

A sample service definition is:

{
    "name": "GraphQL",
    "description": "GraphQL policies service",
    "ref": "github.com/project-flogo/microgateway/activity/graphql"
}

An example step that invokes JQL service using a GraphQL request from a HTTP trigger is:

{
    "service": "GraphQL",
    "input": {
        "query": "=$.payload.content",
        "schemaFile": "schema.graphql",
        "maxQueryDepth": 2
    }
}

Utilizing and extracting the response values can be seen in a conditional evaluation:

{
    "if": "$.GraphQL.outputs.error == true",
    "error": true,
    "output": {
        "code": 200,
        "data": {
            "error": "=$.GraphQL.outputs.errorMessage"
        }
    }
}

Maximum Query Depth (mode: a)

This mode allows to prevent clients from abusing deep query depth, Knowing your schema might give you an idea of how deep a legitimate query can go. example bad query:

query badquery {            #depth 0
  author() {                #depth 1
    posts {                 #depth 2
      author {              #depth 3
        posts {             #depth 4
          author {          #depth 5
          }
        }
      }
    }
  }
}

gateway configured with maxQueryDepth to 3 would consider above query too deep and the query is invalid.

Throttle based on server time (mode: b)

This mode allows to set up a maximum server time a client can use over a certain time frame and how much server time is added to the client over time.

Example:

{
  "name": "GraphQL",
  "description": "GraphQL policies service",
  "ref": "github.com/project-flogo/microgateway/activity/graphql",
  "settings": {
    "mode": "b",
    "limit": "1000-200-2000"
    }
}

In the above graphql service maximum server time is set to 1000ms and client gains 200ms of server time per 2000ms

TODO

  • Policy based on GraphQL query complexity
  • Throttling Based on Query Complexity

# Packages

No description provided by the author
No description provided by the author

# Functions

New creates new Activity.

# Constants

GqlModeA GraphQL policy based on input query depth.
GqlModeB GraphQL policy based on utilized server time.

# Structs

Activity is an GraphQLActivity inputs : {message} outputs: none.
Context graphql context.
Input input meta data.
No description provided by the author
Settings settings for the GraphQL policy service.