# README


title: GraphQL weight: 4706

tibco-graphql

This trigger serves as a GraphQL HTTP endpoint. You can pass in GraphQL queries via GET and POST requests.

Installation

flogo install github.com/TIBCOSoftware/flogo-contrib/trigger/graphql

Schema

Settings, Outputs and Endpoint:

    "settings": [
      {
        "name": "port",
        "type": "integer",
        "required": true
      },
      {
        "name": "types",
        "type": "array",
        "required": true
      },
      {
        "name": "schema",
        "type": "object",
        "required": true
      },
      {
        "name": "operation",
        "type": "string",
        "required": false,
        "value": "QUERY",
        "allowed" : ["QUERY"]
      },
      {
        "name": "path",
        "type": "string",
        "required" : true
      }
    ],
    "output": [
      {
        "name": "args",
        "type": "any"
      }
    ],
    "reply": [
      {
        "name": "data",
        "type": "any"
      }
    ],
    "handler": {
      "settings": [
        {
          "name": "resolverFor",
          "type": "string",
          "required" : true
        }
      ]
    }

Settings

Trigger:

SettingDescription
portThe port to listen on
typesThe GraphQL object types
schemaThe GraphQL schema
operationThe GraphQL operation to support, QUERY is the only valid option
pathThe HTTP resource path

Output:

SettingDescription
argsThe GraphQL query arguments

Handler:

SettingDescription
resolverForIndicates that this handler can resolve the specified GraphQL field. The value here must match a field from the schema.

Example GraphQL Types

        "types": [
          {
            "Name": "user",
            "Fields": {
              "id": {
                "Type": "graphql.String"
              },
              "name": {
                "Type": "graphql.String"
              }
            }
          },
          {
            "Name": "address",
            "Fields": {
              "street": {
                "Type": "graphql.String"
              },
              "number": {
                "Type": "graphql.String"
              }
            }
          }
        ]

Example GraphQL Schemas

        "schema": {
          "Query": {
            "Name": "Query",
            "Fields": {
              "user": {
                "Type": "user",
                "Args": {
                  "id": {
                    "Type": "graphql.String"
                  },
                  "name": {
                    "Type": "graphql.String"
                  }
                }
              },
              "address": {
                "Type": "address",
                "Args": {
                  "street": {
                    "Type": "graphql.String"
                  },
                  "number": {
                    "Type": "graphql.String"
                  }
                }
              }
            }
          }
        }

Note that if user and address are both to be resolvable, then a handler, which specifies address and user in the resolverFor field is required. Currently one Flogo action can be used to resolve a single GraphQL field, you may resolve as many fields as required with multiple handlers.

Example Application

To build the example application, follow the steps below:

flogo create -flv github.com/TIBCOSoftware/flogo-contrib/action/flow@master,github.com/TIBCOSoftware/flogo-lib/engine@master -f ~/Downloads/example.json

Note that the above command assumes that you've downloaded the example.json and placed it in your Downloads dir.

cd Example
flogo build

Now, run the application:

cd bin
./Example

To test the application, send a GET request:

curl -g 'http://localhost:7777/graphql?query={user(name:"Matt"){name,id},address{street,number}}'

The following response will be returned:

{"data":{"address":{"number":"123","street":"Main St."},"user":{"id":"123","name":"Matt"}}}

# Functions

NewFactory create a new Trigger factory.
NewServer create a new server instanceparam server - is a instance of http.Server, can be nil and a default one will be created.

# Constants

No description provided by the author

# Structs

GraphQLFactory Trigger factory.
GraphQLTrigger trigger struct.
Server the server structure.