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:
Setting | Description |
---|---|
port | The port to listen on |
types | The GraphQL object types |
schema | The GraphQL schema |
operation | The GraphQL operation to support, QUERY is the only valid option |
path | The HTTP resource path |
Output:
Setting | Description |
---|---|
args | The GraphQL query arguments |
Handler:
Setting | Description |
---|---|
resolverFor | Indicates 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"}}}
Documentation ¶
Index ¶
Constants ¶
const (
REST_CORS_PREFIX = "GRAPHQL_TRIGGER"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type GraphQLFactory ¶
type GraphQLFactory struct {
// contains filtered or unexported fields
}
GraphQLFactory Trigger factory
type GraphQLTrigger ¶
type GraphQLTrigger struct {
// contains filtered or unexported fields
}
GraphQLTrigger trigger struct
func (*GraphQLTrigger) Initialize ¶
func (t *GraphQLTrigger) Initialize(ctx trigger.InitContext) error
func (*GraphQLTrigger) Metadata ¶
func (t *GraphQLTrigger) Metadata() *trigger.Metadata
Metadata implements trigger.Trigger.Metadata
func (*GraphQLTrigger) Start ¶
func (t *GraphQLTrigger) Start() error
func (*GraphQLTrigger) Stop ¶
func (t *GraphQLTrigger) Stop() error
Stop implements util.Managed.Stop
type Server ¶
Server the server structure
func NewServer ¶
NewServer create a new server instance param server - is a instance of http.Server, can be nil and a default one will be created
func (*Server) IsStarted ¶
IsStarted checks if the server is started will return true even if the server is stopped but there are still some requests to finish