graphql

package
v0.0.0-...-fe2996b Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: BSD-3-Clause Imports: 25 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/project-flogo/graphql/trigger/graphql

Schema

Settings, Outputs and Endpoint:

    "settings": [
      {
        "name": "port",
        "type": "integer",
        "required": true
      },
      {
        "name": "path",
        "type": "string",
        "required" : true
      },
      {
        "name": "secureConnection",
        "type": "boolean",
        "value": false
      },
      {
        "name": "serverKey",
        "type": "string"
      },
      {
        "name": "caCertificate",
        "type": "string"
      },
      {
        "name": "graphqlSchema",
        "type": "string",
        "required": true
      }
    ],
    "handler": {
      "settings": [
        {
         "name": "operation",
         "type": "string",
         "required": false,
         "value": "Query",
         "allowed" : ["Query", "Mutation"]
       },
       {
          "name": "resolverFor",
          "type": "string",
          "required" : true
        }
      ]
    },
    "output": [
      {
        "name": "arguments",
        "type": "object"
      }
    ],
    "reply": [
      {
        "name": "data",
        "type": "object"
      }
    ]

Settings

Trigger:

Setting Description
port The port to listen on
path The HTTP resource path
secureConnection Set to "true" for a secure connection
serverKey A PEM encoded private key file
caCertificate A PEM encoded CA or Server certificate file
schema The GraphQL schema

Handler:

Setting Description
operation The GraphQL operation to support, Query and Mutation are the only valid values
resolverFor Indicates that this handler can resolve the specified GraphQL field. The value here must match a field from the schema.

Map to flow inputs

  1. Create input parameter "arguments" of type "object" at action input/output settings.
  2. In Map to flow inputs, map Trigger Output "arguments" of type "any" to Flow Input Params "arguments" of type "object"

Map from flow output

  1. Create output parameter "data" of type "object" at action input/output settings.
  2. In Map from flow output, map Flow Output "data" of type "object" to Trigger Response "data" of type "any"

Example GraphQL Schemas

type User {
    id: Int!
    name: String
    email: String
    address: Address
    phone: String
}

type Address {
    street: String
    suite: String
    city: String
    zipcode: String
}

type Query {
    GetUser(userId: Int): User
}

schema {
    query: Query
}

Note: When entering the schema into the text box field of Flogo Web OSS Studio, all the new lines("\n") need to be replaced by space(" "). 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 -f example1.json
cd Example1
flogo build

Now, run the application:

cd bin
./Example1

To test the application, send a GET request:

curl -g 'http://localhost:7879/graphql?query={GetUser(userId:1){name,id},address{city,zipcode}}'

The following response will be returned:

{"data": {"GetUser": {"address": {"city": "Gwenborough","zipcode": "92998-3874"},"id": 1,"name": "Leanne Graham"}}}

Additional example applications available under samples folder here.

Documentation

Index

Constants

View Source
const (

	//Info Messages
	TriggerInitialize = 1001
	StartingServer    = 1002
	ServerProperties  = 1003
	CORSPreFlight     = 1004

	//Debug Message
	ExecutingMethod        = 2001
	InterfaceUnionResolver = 2002
	QueryType              = 2003
	MutationType           = 2004
	Schema                 = 2005
	ReceivedRequest        = 2006
	FieldResolver          = 2007
	GraphQLRequest         = 2008
	GraphQLResponse        = 2009
	FlowReturnValue        = 2010

	//Error Messages
	DefaultError              = 4001
	ParsingSchemaError        = 4002
	BuildingSchemaError       = 4003
	MissingServerKeyError     = 4004
	GraphqlError              = 4005
	ErrorProcessingRequest    = 4006
	ErrorLoadingCertsFromFile = 4007
)

Constants

Variables

This section is empty.

Functions

func CoerceScalarType

func CoerceScalarType(typ string) *graphql.Scalar

CoerceScalarType converts type to graphql.Scalar

func CoerceType

func CoerceType(typ ast.Type, typMap map[string]graphql.Type) graphql.Type

CoerceType converts ast.Type to graphql.Type

func GetAstStringValue

func GetAstStringValue(val interface{}) string

GetAstStringValue returns string value of ast.StringValue object

func GetError

func GetError(errConst int, triggerName string, params ...interface{}) error

GetError to create error -- Since Error is not implemented for trigger, error code is not built

func GetInterfaceOrUnionType

func GetInterfaceOrUnionType(typ graphql.Output) graphql.Type

GetInterfaceOrUnionType returns the interface or union type from a given Output type

func GetMessage

func GetMessage(msgConst int, params ...interface{}) string

GetMessage to get error message

func GetValue

func GetValue(val ast.Value) interface{}

GetValue returns value of ast.Value

func IsScalarType

func IsScalarType(t string) bool

IsScalarType returns true for scalar types

Types

type Factory

type Factory struct {
}

Factory for trigger

func (*Factory) Metadata

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

Metadata implements trigger.Factory.Metadata

func (*Factory) New

func (*Factory) New(config *trigger.Config) (trigger.Trigger, error)

New implements trigger.Factory.New

type HandlerSettings

type HandlerSettings struct {
	Operation   string `md:"operation,required,allowed(Query,Mutation)"` // GraphQL Operation to be performed
	ResolverFor string `md:"resolverFor,required"`                       // Field name from selected operation
}

HandlerSettings for trigger

type Output

type Output struct {
	Arguments map[string]interface{} `md:"arguments"` // The input arguments to the field of the operation
}

Output of the trigger -- Input into the flow

func (*Output) FromMap

func (o *Output) FromMap(values map[string]interface{}) error

FromMap from the trigger Output

func (*Output) ToMap

func (o *Output) ToMap() map[string]interface{}

ToMap to the trigger Output

type Reply

type Reply struct {
	Data map[string]interface{} `md:"data"` // The data to reply with
}

Reply from the trigger

func (*Reply) FromMap

func (r *Reply) FromMap(values map[string]interface{}) error

FromMap from the trigger Reply

func (*Reply) ToMap

func (r *Reply) ToMap() map[string]interface{}

ToMap to the trigger Reply

type RequestOptions

type RequestOptions struct {
	Query         string                 `json:"query" url:"query" schema:"query"`
	Variables     map[string]interface{} `json:"variables" url:"variables" schema:"variables"`
	OperationName string                 `json:"operationName" url:"operationName" schema:"operationName"`
}

RequestOptions struct for graphql request

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

type Settings

type Settings struct {
	Port             int    `md:"port,required"`             // The port to listen on for requests
	Path             string `md:"path,required"`             // The HTTP resource path
	SecureConnection bool   `md:"secureConnection,required"` // Set to "true" for a secure connection
	ServerKey        string `md:"serverKey"`                 // A PEM encoded private key file
	CACertificate    string `md:"caCertificate"`             // A PEM encoded CA or Server certificate file
	GraphQLSchema    string `md:"graphqlSchema,required"`    // The GraphQL schema for the trigger
}

Settings for trigger

type Trigger

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

Trigger is a stub for the GraphQLTrigger implementation

func (*Trigger) Initialize

func (t *Trigger) Initialize(ctx trigger.InitContext) error

Initialize trigger

func (*Trigger) Start

func (t *Trigger) Start() error

Start implements util.Managed.Start

func (*Trigger) Stop

func (t *Trigger) Stop() error

Stop implements util.Managed.Stop

Directories

Path Synopsis
Package cors to validate CORS requests and provide the correct headers in the response
Package cors to validate CORS requests and provide the correct headers in the response

Jump to

Keyboard shortcuts

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