Skip to content

Commit

Permalink
fix: don't define the @removeNullVariables directive in the base sche…
Browse files Browse the repository at this point in the history
…ma (#577)

Support it, but require the caller to declare it themselves if they want
to use it.

References wundergraph/wundergraph#985

Also, remove a couple of deprecated usages of ioutil
  • Loading branch information
fiam committed Aug 18, 2023
1 parent e9eb3a8 commit 6239b61
Show file tree
Hide file tree
Showing 17 changed files with 14 additions and 221 deletions.
19 changes: 0 additions & 19 deletions pkg/asttransform/baseschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE
"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.
A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.
query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}
Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }
So upstream will receive the following variables:
{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION
"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
19 changes: 0 additions & 19 deletions pkg/asttransform/fixtures/complete.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.

query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }

So upstream will receive the following variables:

{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
19 changes: 0 additions & 19 deletions pkg/asttransform/fixtures/custom_query_name.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.

query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }

So upstream will receive the following variables:

{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
19 changes: 0 additions & 19 deletions pkg/asttransform/fixtures/mutation_only.golden
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.

query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }

So upstream will receive the following variables:

{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
19 changes: 0 additions & 19 deletions pkg/asttransform/fixtures/schema_missing.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.

query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }

So upstream will receive the following variables:

{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
19 changes: 0 additions & 19 deletions pkg/asttransform/fixtures/simple.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.

query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }

So upstream will receive the following variables:

{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
19 changes: 0 additions & 19 deletions pkg/asttransform/fixtures/subscription_only.golden
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.

query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }

So upstream will receive the following variables:

{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
19 changes: 0 additions & 19 deletions pkg/asttransform/fixtures/subscription_renamed.golden
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.

query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }

So upstream will receive the following variables:

{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
19 changes: 0 additions & 19 deletions pkg/asttransform/fixtures/with_mutation_subscription.golden
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,6 @@ directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE

"""
The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.

A potential use-case could be that you have a graphql upstream which is not accepting null values for variables.
By enabling this directive all variables with null values will be removed from upstream query.

query ($say: String, $name: String) @removeNullVariables {
hello(say: $say, name: $name)
}

Directive will transform variables json and remove top level null values.
{ "say": null, "name": "world" }

So upstream will receive the following variables:

{ "name": "world" }
"""
directive @removeNullVariables on QUERY | MUTATION

"""
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
In some cases, you need to provide options to alter GraphQL's execution behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (
)

func TestGraphQLDataSource(t *testing.T) {
// XXX: Directive needs to be explicitly declared
t.Run("@removeNullVariables directive", RunTest(`
directive @removeNullVariables on QUERY | MUTATION
schema {
query: Query
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,6 @@
}
],
"isRepeatable": false
},
{
"name": "removeNullVariables",
"description": "The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.\n\nA potential use-case could be that you have a graphql upstream which is not accepting null values for variables.\nBy enabling this directive all variables with null values will be removed from upstream query.\n\nquery ($say: String, $name: String) @removeNullVariables {\n\thello(say: $say, name: $name)\n}\n\nDirective will transform variables json and remove top level null values.\n{ \"say\": null, \"name\": \"world\" }\n\nSo upstream will receive the following variables:\n\n{ \"name\": \"world\" }",
"locations": [
"QUERY",
"MUTATION"
],
"args": [],
"isRepeatable": false
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,6 @@
}
],
"isRepeatable": false
},
{
"name": "removeNullVariables",
"description": "The @removeNullVariables directive allows you to remove variables with null value from your GraphQL Query or Mutation Operations.\n\nA potential use-case could be that you have a graphql upstream which is not accepting null values for variables.\nBy enabling this directive all variables with null values will be removed from upstream query.\n\nquery ($say: String, $name: String) @removeNullVariables {\n\thello(say: $say, name: $name)\n}\n\nDirective will transform variables json and remove top level null values.\n{ \"say\": null, \"name\": \"world\" }\n\nSo upstream will receive the following variables:\n\n{ \"name\": \"world\" }",
"locations": [
"QUERY",
"MUTATION"
],
"args": [],
"isRepeatable": false
}
]
}
16 changes: 8 additions & 8 deletions pkg/execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/http/httputil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -255,7 +255,7 @@ func TestExecution(t *testing.T) {
Value: []byte(graphQL2.URL + "/graphql"),
},
&datasource.StaticVariableArgument{
Name: literal.QUERY,
Name: literal.QUERY,
Value: []byte(`query q1($id: String!){userPets(id: $id){ __typename name nickname... on Dog {woof} ... on Cat {meow}}}`),
},
&datasource.ObjectVariableArgument{
Expand Down Expand Up @@ -582,7 +582,7 @@ func TestExecution(t *testing.T) {
goldie.Assert(t, "execution", pretty)
if t.Failed() {

fixture, err := ioutil.ReadFile("./fixtures/execution.golden")
fixture, err := os.ReadFile("./fixtures/execution.golden")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -784,7 +784,7 @@ func genField() Field {
Value: []byte("localhost:8002/graphql"),
},
&datasource.StaticVariableArgument{
Name: literal.QUERY,
Name: literal.QUERY,
Value: []byte(`query q1($id: String!){userPets(id: $id){ __typename name nickname... on Dog {woof} ... on Cat {meow}}}`),
},
&datasource.ObjectVariableArgument{
Expand Down Expand Up @@ -1251,7 +1251,7 @@ func TestExecutor_ObjectVariables(t *testing.T) {
return
}

got, err := ioutil.ReadAll(r.Body)
got, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1999,7 +1999,7 @@ func TestExecutor_HTTPJSONDataSourceWithBody(t *testing.T) {
return
}

data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
return
Expand Down Expand Up @@ -2491,7 +2491,7 @@ func TestExecutor_HTTPJSONDataSourceWithBodyComplexPlayload(t *testing.T) {
return
}

data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
return
Expand Down Expand Up @@ -3009,7 +3009,7 @@ func TestExecutor_Introspection(t *testing.T) {

goldie.Assert(t, "introspection_execution", response)
if t.Failed() {
fixture, err := ioutil.ReadFile("./fixtures/introspection_execution.golden")
fixture, err := os.ReadFile("./fixtures/introspection_execution.golden")
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit 6239b61

Please sign in to comment.