Skip to content

Commit

Permalink
adds context support - #14
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-ramon committed Jan 7, 2016
1 parent 40a2054 commit d904a12
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion examples/starwars/schema.go
Expand Up @@ -3,6 +3,7 @@ package starwars
import (
"github.com/graphql-go/graphql"
"github.com/graphql-go/relay"
"golang.org/x/net/context"
)

/**
Expand Down Expand Up @@ -291,7 +292,7 @@ func init() {
},
},
},
MutateAndGetPayload: func(inputMap map[string]interface{}, info graphql.ResolveInfo) map[string]interface{} {
MutateAndGetPayload: func(inputMap map[string]interface{}, info graphql.ResolveInfo, ctx context.Context) map[string]interface{} {
// `inputMap` is a map with keys/fields as specified in `InputFields`
// Note, that these fields were specified as non-nullables, so we can assume that it exists.
shipName := inputMap["shipName"].(string)
Expand Down
5 changes: 3 additions & 2 deletions mutation.go
Expand Up @@ -2,9 +2,10 @@ package relay

import (
"github.com/graphql-go/graphql"
"golang.org/x/net/context"
)

type MutationFn func(inputMap map[string]interface{}, info graphql.ResolveInfo) map[string]interface{}
type MutationFn func(inputMap map[string]interface{}, info graphql.ResolveInfo, ctx context.Context) map[string]interface{}

/*
A description of a mutation consumable by mutationWithClientMutationId
Expand Down Expand Up @@ -75,7 +76,7 @@ func MutationWithClientMutationID(config MutationConfig) *graphql.Field {
input = inputVal
}
}
payload := config.MutateAndGetPayload(input, p.Info)
payload := config.MutateAndGetPayload(input, p.Info, p.Context)
if clientMutationID, ok := input["clientMutationId"]; ok {
payload["clientMutationId"] = clientMutationID
}
Expand Down
12 changes: 7 additions & 5 deletions mutation_test.go
@@ -1,13 +1,15 @@
package relay_test

import (
"reflect"
"testing"
"time"

"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/testutil"
"github.com/graphql-go/relay"
"reflect"
"testing"
"time"
"golang.org/x/net/context"
)

func testAsyncDataMutation(resultChan *chan int) {
Expand All @@ -24,7 +26,7 @@ var simpleMutationTest = relay.MutationWithClientMutationID(relay.MutationConfig
Type: graphql.Int,
},
},
MutateAndGetPayload: func(inputMap map[string]interface{}, info graphql.ResolveInfo) map[string]interface{} {
MutateAndGetPayload: func(inputMap map[string]interface{}, info graphql.ResolveInfo, ctx context.Context) map[string]interface{} {
return map[string]interface{}{
"result": 1,
}
Expand All @@ -40,7 +42,7 @@ var simplePromiseMutationTest = relay.MutationWithClientMutationID(relay.Mutatio
Type: graphql.Int,
},
},
MutateAndGetPayload: func(inputMap map[string]interface{}, info graphql.ResolveInfo) map[string]interface{} {
MutateAndGetPayload: func(inputMap map[string]interface{}, info graphql.ResolveInfo, ctx context.Context) map[string]interface{} {
c := make(chan int)
go testAsyncDataMutation(&c)
result := <-c
Expand Down

1 comment on commit d904a12

@bsr203
Copy link

@bsr203 bsr203 commented on d904a12 Jan 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you rock :-) too quick :-) thanks.

Please sign in to comment.