Skip to content

nrfta/go-mgql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)