graphql

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: BSD-3-Clause Imports: 15 Imported by: 0

README

GraphQL module for the Modulus framework

This is a module for the Modulus framework that lets developers use graphql API in their projects. It is a wrapper for the library https://gqlgen.com/

Adding the module

To integrate the module follow next steps:

  • Add ENV variables from .env.dist to your root .env file
  • Copy gqlgen.yml.dist to your project root directory as gqlgen.yml
  • In the gqlgen.yml change package name "boilerplate" to the name of your package
  • Copy graph.dist directory to the folder "internal" of your project as graph
  • In some of your modules add a graphql file in the root of your module's folder with a schema. For example
extend type Query {
    user(id: String!): User
}
extend type Mutation {
    register(email: String!, name: String!): User
}

type User {
    id: String!
    email: String!
    name: String!
}
  • Call go run github.com/99designs/gqlgen generate --config gqlgen.yml to generate Golang code of resolvers and models
  • Copy graph/config.go.dist to the graph/config.go. Fix package names in imports, and add this module config to the list of modules of your application.
  • Check if the router, for example https://github.com/debugger84/modulus-router-httprouter is added as a module to your application

Documentation

Index

Constants

View Source
const GraphQlPanic application.ActionErrorKey = `GraphQlPanic`

Variables

This section is empty.

Functions

func ConvertToGraphQlBackendValidationError

func ConvertToGraphQlBackendValidationError(
	ctx context.Context,
	err ExtendedValidationError,
) *gqlerror.Error

func ConvertToGraphQlError

func ConvertToGraphQlError(
	ctx context.Context,
	err ExtendedError,
) *gqlerror.Error

func CreateGraphQlError

func CreateGraphQlError(
	ctx context.Context,
	msg string,
	status string,
	errCode int,
) *gqlerror.Error

func CreateGraphQlErrorWithPlaceholders

func CreateGraphQlErrorWithPlaceholders(
	ctx context.Context,
	msg string,
	status string,
	errCode int,
	placeHolders map[string]interface{},
) *gqlerror.Error

func GetError

func GetError(errs []error) error

Types

type ClientError

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

func (*ClientError) ErrCode

func (m *ClientError) ErrCode() int

func (*ClientError) Error

func (m *ClientError) Error() string

func (*ClientError) Msg

func (m *ClientError) Msg() string

func (*ClientError) Status

func (m *ClientError) Status() string

type ExtendedError

type ExtendedError interface {
	Msg() string
	Status() string
	ErrCode() int
}

type ExtendedValidationError

type ExtendedValidationError interface {
	ExtendedError
	Errors() map[string]string
	Extra() map[string]interface{}
}

type GraphQlServer

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

func NewGraphQLServer

func NewGraphQLServer(
	config *ModuleConfig,
	logger application.Logger,
	es graphql.ExecutableSchema,
) *GraphQlServer

func (*GraphQlServer) ApiHandler

func (f *GraphQlServer) ApiHandler() http.HandlerFunc

func (GraphQlServer) GetServer

func (f GraphQlServer) GetServer() *handler.Server

func (*GraphQlServer) PlaygroundHandler

func (f *GraphQlServer) PlaygroundHandler(title string, endpoint string) http.HandlerFunc

type ModuleConfig

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

func NewModuleConfig

func NewModuleConfig() *ModuleConfig

func (*ModuleConfig) InitConfig

func (s *ModuleConfig) InitConfig(config application.Config) error

func (*ModuleConfig) ModuleRoutes

func (s *ModuleConfig) ModuleRoutes() []application.RouteInfo

func (*ModuleConfig) OnStart

func (s *ModuleConfig) OnStart() error

func (*ModuleConfig) ProvidedServices

func (s *ModuleConfig) ProvidedServices() []interface{}

func (*ModuleConfig) SetContainer

func (s *ModuleConfig) SetContainer(container *dig.Container)

Directories

Path Synopsis
graph.dist

Jump to

Keyboard shortcuts

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