graphql

package
v0.5.8-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2019 License: BSD-3-Clause Imports: 17 Imported by: 0

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

View Source
const (
	REST_CORS_PREFIX = "GRAPHQL_TRIGGER"
)

Variables

This section is empty.

Functions

func NewFactory

func NewFactory(md *trigger.Metadata) trigger.Factory

NewFactory create a new Trigger factory

Types

type GraphQLFactory

type GraphQLFactory struct {
	// contains filtered or unexported fields
}

GraphQLFactory Trigger factory

func (*GraphQLFactory) New

func (t *GraphQLFactory) New(config *trigger.Config) trigger.Trigger

New Creates a new trigger instance for a given id

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

type Server struct {
	*http.Server
	// contains filtered or unexported fields
}

Server the server structure

func NewServer

func NewServer(addr string, handler http.Handler) *Server

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) InstanceID

func (s *Server) InstanceID() string

InstanceID the server instance id

func (*Server) IsStarted

func (s *Server) IsStarted() bool

IsStarted checks if the server is started will return true even if the server is stopped but there are still some requests to finish

func (*Server) Start

func (s *Server) Start() error

Start this will start server command isn't blocking, will exit after run

func (*Server) Stop

func (s *Server) Stop() error

Stop sends stop command to the server

func (*Server) WaitStop

func (s *Server) WaitStop(timeout time.Duration) error

WaitStop waits until server is stopped and all requests are finish timeout - is the time to wait for the requests to finish after the server is stopped will return error if there are still some requests not finished

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL