graphql

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 21 Imported by: 52

README

Flamingo GraphQL

This modul allows the usage of GraphQL services in your Flamingo project.

Example

The module contains a working example that you can try out yourself. See https://github.com/i-love-flamingo/graphql/tree/master/example

Setup Graphql in your Flamingo project

Add the graphql.Module to your projects modules.

Generate the local code by running go run main.go graphql. Better is to add the following lines to your project main file:

//go:generate rm -f graphql/generated.go
//go:generate go run -tags graphql main.go graphql

Then you can run go generate . instead of go run main.go graphql

After this the project specific graphql code is generated inside the folder graphql

You then also need to add the generated local Module to your main project file:


import (
    projectGraphql "yourpoject-namespace/graphql"
)

....
   new(projectGraphql.Module),
....

Now when you start your application you are able to use the graphql API and the graphql console. See the example folder for a complete example on how to use flamingo.me/graphql.

The next thing you need to do is to add Resolver to the file resolver.go:

Resolver and Modifier

Everything needs to be resolved, unless gqlgen can figure something out on its own.

Best practive here is to provide default resolvers in your code, which can be used via embedding. See example/user for an example UserQuery resolver.

Suggested Naming Conventions

We recommend to namespace your Types and Type extensions with the Project name. For Flamingo Core Framework GraphQL Schema we use the prefix Core_ and for Flamingo Commerce we use Commerce_

Resources

Learn GraphQL: https://graphql.org/learn/

GraphQL Specification: https://graphql.github.io/graphql-spec/June2018/#sec-Schema

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlamingoResolver

func FlamingoResolver(_ context.Context) (*string, error)

FlamingoResolver always returns "flamingo" for default schemas.

func Generate

func Generate(services []Service, basePath string, schemaBasePath string) error

Generate runs the graphql generation for the defined services

func MarshalFloat

func MarshalFloat(f big.Float) graphql.Marshaler

MarshalFloat for graphql Float scalars to be compatible with big.Float

func UnmarshalFloat

func UnmarshalFloat(v interface{}) (big.Float, error)

UnmarshalFloat for graphql Float scalars to be compatible with big.Float

Types

type FlamingoQueryResolver

type FlamingoQueryResolver struct{}

FlamingoQueryResolver always resolves to the string "flamingo" for the default schemas.

func (*FlamingoQueryResolver) Flamingo

func (*FlamingoQueryResolver) Flamingo(ctx context.Context) (*string, error)

Flamingo field resolver

type ModelMap

type ModelMap map[string]interface{}

ModelMap is a helper to quickly create map[string]TypeMapEntry for graphql type mappings.

func (ModelMap) Models

func (m ModelMap) Models() map[string]config.TypeMapEntry

Models creates the references via reflection

type ModelMapEntry

type ModelMapEntry struct {
	Type   interface{}
	Fields map[string]string
}

ModelMapEntry can be used to create a more detailed ModelMap.

type Module

type Module struct{}

Module defines the graphql entry point and binds the graphql command and routes

func (*Module) Configure

func (*Module) Configure(injector *dingo.Injector)

Configure sets up dingo

func (*Module) DefaultConfig

func (m *Module) DefaultConfig() flamingoConfig.Map

DefaultConfig for this module

type Service

type Service interface {
	Schema() []byte
	Models() map[string]config.TypeMapEntry
}

Service defines the bind point for graphql services

Directories

Path Synopsis
user/interfaces/graphql
Package graphql Code generated by go-bindata.
Package graphql Code generated by go-bindata.
Package templates Code generated by go-bindata.
Package templates Code generated by go-bindata.

Jump to

Keyboard shortcuts

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