graphql

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 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.ErrorIdentifier = `GraphQlPanic`

Variables

This section is empty.

Functions

func FromCommonErr added in v0.0.3

func FromCommonErr(
	ctx context.Context,
	error *application.CommonError,
) *gqlerror.Error

func FromValidationErr added in v0.0.3

func FromValidationErr(
	ctx context.Context,
	errors []application.ValidationError,
) *gqlerror.Error

Types

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