-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69 operation name is not forwarded for persisted queries (#83)
Make sure to send out the operation name of a persisted operation to the upstream --------- Co-authored-by: ldebruijn <[email protected]>
- Loading branch information
Showing
20 changed files
with
216 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,5 @@ TODO.md | |
# ignore binary | ||
main | ||
|
||
store/ | ||
schema.graphql | ||
store/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ersisted_operations/gcp_storage_loader.go → ...persistedoperations/gcp_storage_loader.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package persistedoperations // nolint:revive | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// MemoryLoader is a loader for testing purposes | ||
// It allows the user to specify operations in memory | ||
type MemoryLoader struct { | ||
store map[string]PersistedOperation | ||
} | ||
|
||
func newMemoryLoader(store map[string]PersistedOperation) *MemoryLoader { | ||
return &MemoryLoader{ | ||
store: store, | ||
} | ||
} | ||
|
||
func (d *MemoryLoader) Load(_ context.Context) (map[string]PersistedOperation, error) { | ||
return d.store, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package persistedoperations | ||
|
||
import "strings" | ||
|
||
type PersistedOperation struct { | ||
Operation string | ||
Name string | ||
} | ||
|
||
func NewPersistedOperation(operation string) PersistedOperation { | ||
name := extractOperationNameFromPersistedOperation(operation) | ||
return PersistedOperation{ | ||
Operation: operation, | ||
Name: name, | ||
} | ||
} | ||
|
||
func extractOperationNameFromPersistedOperation(payload string) string { | ||
firstSpace := strings.Index(payload, " ") | ||
firstBracket := strings.Index(payload, "{") | ||
firstParenthesis := strings.Index(payload, "(") | ||
|
||
until := firstBracket | ||
if firstParenthesis < firstBracket { | ||
until = firstParenthesis | ||
} | ||
|
||
if firstSpace > until || until == -1 { | ||
return "" | ||
} | ||
|
||
return strings.TrimSpace(payload[firstSpace+1 : until]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package persistedoperations | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestNewPersistedOperation(t *testing.T) { | ||
type args struct { | ||
operation string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want PersistedOperation | ||
}{ | ||
{ | ||
name: "extracts operation from query", | ||
args: args{ | ||
operation: "query ProductQuery{ product(id: 1) { id title as } }", | ||
}, | ||
want: PersistedOperation{ | ||
Operation: "query ProductQuery{ product(id: 1) { id title as } }", | ||
Name: "ProductQuery", | ||
}, | ||
}, | ||
{ | ||
name: "extracts operation from mutation", | ||
args: args{ | ||
operation: "mutation ProductQuery{ product(id: 1) { id title as } }", | ||
}, | ||
want: PersistedOperation{ | ||
Operation: "mutation ProductQuery{ product(id: 1) { id title as } }", | ||
Name: "ProductQuery", | ||
}, | ||
}, | ||
{ | ||
name: "no operation name when not present", | ||
args: args{ | ||
operation: "mutation { product(id: 1) { id title as } }", | ||
}, | ||
want: PersistedOperation{ | ||
Operation: "mutation { product(id: 1) { id title as } }", | ||
Name: "", | ||
}, | ||
}, | ||
{ | ||
name: "no operation name when no space between type and bracket", | ||
args: args{ | ||
operation: "mutation{ product(id: 1) { id title as } }", | ||
}, | ||
want: PersistedOperation{ | ||
Operation: "mutation{ product(id: 1) { id title as } }", | ||
}, | ||
}, | ||
{ | ||
name: "excludes operation arguments", | ||
args: args{ | ||
operation: "query Foobar($some: Int, $value: String){ product(id: 1) { id title as } }", | ||
}, | ||
want: PersistedOperation{ | ||
Operation: "query Foobar($some: Int, $value: String){ product(id: 1) { id title as } }", | ||
Name: "Foobar", | ||
}, | ||
}, | ||
{ | ||
name: "no weird stuff when getting a completely malformed string", | ||
args: args{ | ||
operation: "", | ||
}, | ||
want: PersistedOperation{ | ||
Operation: "", | ||
Name: "", | ||
}, | ||
}, | ||
{ | ||
name: "handles white space around operation name", | ||
args: args{ | ||
operation: "query Foobar ($some: Int, $value: String){ product(id: 1) { id title as } }", | ||
}, | ||
want: PersistedOperation{ | ||
Operation: "query Foobar ($some: Int, $value: String){ product(id: 1) { id title as } }", | ||
Name: "Foobar", | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.want, NewPersistedOperation(tt.args.operation), "NewPersistedOperation(%v)", tt.args.operation) | ||
}) | ||
} | ||
} |
Oops, something went wrong.