mgql

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 10 Imported by: 0

README

Go Mock Graphql (go-mgql)

Library to mock graphql requests.

Usage

Create a new mgql instance:
m := mgql.New()
m.Query("GetAccount", func(ctx mgql.Context) {
	ctx.Data(
		mgql.Map{
			"account": mgql.Map{
				"id": ctx.Variables["id"],
			},
		},
	)
})
Pass the HTTP handler to a test server:
testServer := httptest.NewServer(m.Handler())
Reset mgql registry before each test:
ginkgo.BeforeEach(func() {
	m.Reset()
})
Overwrite default resolvers at your test:
It("creates service appointment when onboarding", func() {
  // ...
	m.Query("GetAccount", func(ctx mgql.Context) {
    // ..
	})
  // ... 
})

API

  • func New() *MGQL
  • func (m *MGQL) Handler() http.HandlerFunc
  • func (m *MGQL) Mutation(operationName string, responseResolver ResponseResolver)
  • func (m *MGQL) Query(operationName string, responseResolver ResponseResolver)
  • func (m *MGQL) Reset()
  • func (m *MGQL) SpyMutation(operationName string, responseResolver ResponseResolver)
  • func (m *MGQL) SpyQuery(operationName string, responseResolver ResponseResolver)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(input interface{}) []byte

Types

type Context

type Context struct {
	Variables map[string]interface{}
	// contains filtered or unexported fields
}

func (*Context) Context

func (c *Context) Context() context.Context

func (*Context) Data

func (c *Context) Data(data interface{})

func (*Context) Error

func (c *Context) Error(err ...error)

func (*Context) GraphqlError

func (c *Context) GraphqlError(err ...*gqlerror.Error)

type MGQL

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

func New

func New() *MGQL

func (*MGQL) Handler

func (m *MGQL) Handler() http.HandlerFunc

func (*MGQL) Mutation

func (m *MGQL) Mutation(operationName string, responseResolver ResponseResolver)

func (*MGQL) Query

func (m *MGQL) Query(operationName string, responseResolver ResponseResolver)

func (*MGQL) Reset

func (m *MGQL) Reset()

func (*MGQL) SpyMutation

func (m *MGQL) SpyMutation(operationName string, responseResolver ResponseResolver)

func (*MGQL) SpyQuery

func (m *MGQL) SpyQuery(operationName string, responseResolver ResponseResolver)

type Map

type Map map[string]interface{}

type ResponseResolver

type ResponseResolver func(ctx Context)

Jump to

Keyboard shortcuts

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