Skip to content

Commit

Permalink
export context data
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsaw committed Jul 28, 2018
1 parent 67f143b commit 2847629
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package resolvers

import "encoding/json"

type context struct {
// ContextData data received from AppSync
type ContextData struct {
Arguments json.RawMessage `json:"arguments"`
Source json.RawMessage `json:"source"`
}

// Invocation data received from AppSync
type Invocation struct {
Resolve string `json:"resolve"`
Context context `json:"context"`
Resolve string `json:"resolve"`
Context ContextData `json:"context"`
}

func (in Invocation) isRoot() bool {
Expand Down
4 changes: 2 additions & 2 deletions invocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _ = Describe("Invocation", func() {
Context("With Arguments", func() {
data := Invocation{
Resolve: "exaple.resolver",
Context: context{
Context: ContextData{
Arguments: json.RawMessage(`{ "foo": "bar" }`),
},
}
Expand All @@ -28,7 +28,7 @@ var _ = Describe("Invocation", func() {
Context("With Source", func() {
data := Invocation{
Resolve: "exaple.resolver",
Context: context{
Context: ContextData{
Source: json.RawMessage(`{ "bar": "foo" }`),
},
}
Expand Down
4 changes: 2 additions & 2 deletions middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var _ = Describe("Middleware", func() {
})
res, err := r.Handle(Invocation{
Resolve: "example.resolver",
Context: context{
Context: ContextData{
Arguments: json.RawMessage(`{"bar":"foo"}`),
},
})
Expand Down Expand Up @@ -124,7 +124,7 @@ var _ = Describe("Middleware", func() {
})
res, err := r.Handle(Invocation{
Resolve: "example.resolver",
Context: context{
Context: ContextData{
Arguments: json.RawMessage(`{"bar":"foo"}`),
},
})
Expand Down
8 changes: 4 additions & 4 deletions repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("Repository", func() {
Context("Matching invocation", func() {
res, err := r.Handle(Invocation{
Resolve: "example.resolver",
Context: context{
Context: ContextData{
Arguments: json.RawMessage(`{"bar":"foo"}`),
},
})
Expand All @@ -39,7 +39,7 @@ var _ = Describe("Repository", func() {
Context("Matching invocation with error", func() {
_, err := r.Handle(Invocation{
Resolve: "example.resolver.with.error",
Context: context{
Context: ContextData{
Arguments: json.RawMessage(`{"bar":"foo"}`),
},
})
Expand All @@ -52,7 +52,7 @@ var _ = Describe("Repository", func() {
Context("Matching invocation with invalid payload", func() {
_, err := r.Handle(Invocation{
Resolve: "example.resolver.with.error",
Context: context{
Context: ContextData{
Arguments: json.RawMessage(`{"bar:foo"}`),
},
})
Expand All @@ -65,7 +65,7 @@ var _ = Describe("Repository", func() {
Context("Not matching invocation", func() {
res, err := r.Handle(Invocation{
Resolve: "example.resolver.not.found",
Context: context{
Context: ContextData{
Arguments: json.RawMessage(`{"bar":"foo"}`),
},
})
Expand Down

0 comments on commit 2847629

Please sign in to comment.