Skip to content

Commit

Permalink
add features section to graphql proxy config (#6298)
Browse files Browse the repository at this point in the history
### **User description**
This PR adds a new `features` section to the GraphQL proxy
configuration. It will allow the enable or disable specific features for
proxy-only mode.

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)


___

### **PR Type**
Enhancement


___

### **Description**
This PR introduces a new `features` section to the GraphQL proxy
configuration:
- Added `features` section to `GraphQLProxyConfig` in
`apidef/api_definitions.go`.
- Introduced `GraphQLProxyFeaturesConfig` struct with
`UseImmutableHeaders` field.
- Updated `DummyAPI` function to include default `features`
configuration.
- Updated GraphQL proxy schema in `apidef/schema.go` to include
`features` section with `use_immutable_headers` property.


___



### **Changes walkthrough** 📝
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Enhancement
</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>api_definitions.go</strong><dd><code>Add features
section to GraphQL proxy configuration.</code>&nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; </dd></summary>
<hr>

apidef/api_definitions.go
<li>Added <code>features</code> section to
<code>GraphQLProxyConfig</code>.<br> <li> Introduced
<code>GraphQLProxyFeaturesConfig</code> struct with
<code>UseImmutableHeaders</code> <br>field.<br> <li> Updated
<code>DummyAPI</code> function to include default <code>features</code>
configuration.<br>


</details>
    

  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6298/files#diff-9961ccc89a48d32db5b47ba3006315ef52f6e5007fb4b09f8c5d6d299c669d67">+10/-0</a>&nbsp;
&nbsp; </td>
</tr>                    

<tr>
  <td>
    <details>
<summary><strong>schema.go</strong><dd><code>Update GraphQL proxy schema
with features section.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; </dd></summary>
<hr>

apidef/schema.go
<li>Added <code>features</code> section to GraphQL proxy schema.<br>
<li> Included <code>use_immutable_headers</code> property in the
schema.<br>


</details>
    

  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6298/files#diff-f8a37bb370eb6fe20063786a5e6ea3d85a5c91d8e289f0b3e045830c4d322095">+8/-0</a>&nbsp;
&nbsp; &nbsp; </td>
</tr>                    
</table></td></tr></tr></tbody></table>

___

> 💡 **PR-Agent usage**:
>Comment `/help` on the PR to get a list of all available PR-Agent tools
and their descriptions
  • Loading branch information
pvormste committed May 23, 2024
1 parent 11d5798 commit e1ea94a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apidef/adapter/asyncapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ const expectedGraphqlConfig = `{
"global_headers": null
},
"proxy": {
"features": {
"use_immutable_headers": false
},
"auth_headers": {},
"request_headers": null,
"use_response_extensions": {
Expand Down
3 changes: 3 additions & 0 deletions apidef/adapter/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ const expectedOpenAPIGraphQLConfig = `{
"global_headers": null
},
"proxy": {
"features": {
"use_immutable_headers": false
},
"auth_headers": {},
"request_headers": null,
"use_response_extensions": {
Expand Down
10 changes: 10 additions & 0 deletions apidef/api_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import (
"github.com/lonelycode/osin"

"github.com/TykTechnologies/storage/persistent/model"

"github.com/TykTechnologies/tyk/internal/event"

"github.com/TykTechnologies/tyk/internal/reflect"

"github.com/TykTechnologies/graphql-go-tools/pkg/execution/datasource"

"github.com/TykTechnologies/gojsonschema"

"github.com/TykTechnologies/tyk/regexp"

"github.com/TykTechnologies/tyk/internal/uuid"
Expand Down Expand Up @@ -847,13 +849,18 @@ type GraphQLResponseExtensions struct {
}

type GraphQLProxyConfig struct {
Features GraphQLProxyFeaturesConfig `bson:"features" json:"features"`
AuthHeaders map[string]string `bson:"auth_headers" json:"auth_headers"`
SubscriptionType SubscriptionType `bson:"subscription_type" json:"subscription_type,omitempty"`
RequestHeaders map[string]string `bson:"request_headers" json:"request_headers"`
UseResponseExtensions GraphQLResponseExtensions `bson:"use_response_extensions" json:"use_response_extensions"`
RequestHeadersRewrite map[string]RequestHeadersRewriteConfig `json:"request_headers_rewrite" bson:"request_headers_rewrite"`
}

type GraphQLProxyFeaturesConfig struct {
UseImmutableHeaders bool `bson:"use_immutable_headers" json:"use_immutable_headers"`
}

type RequestHeadersRewriteConfig struct {
Value string `json:"value" bson:"value"`
Remove bool `json:"remove" bson:"remove"`
Expand Down Expand Up @@ -1294,6 +1301,9 @@ func DummyAPI() APIDefinition {
Version: GraphQLConfigVersion2,
LastSchemaUpdate: nil,
Proxy: GraphQLProxyConfig{
Features: GraphQLProxyFeaturesConfig{
UseImmutableHeaders: true,
},
AuthHeaders: map[string]string{},
},
}
Expand Down
1 change: 1 addition & 0 deletions apidef/oas/oas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func TestOAS_ExtractTo_ResetAPIDefinition(t *testing.T) {
"APIDefinition.GraphQL.Engine.DataSources[0].Config[0]",
"APIDefinition.GraphQL.Engine.GlobalHeaders[0].Key",
"APIDefinition.GraphQL.Engine.GlobalHeaders[0].Value",
"APIDefinition.GraphQL.Proxy.Features.UseImmutableHeaders",
"APIDefinition.GraphQL.Proxy.AuthHeaders[0]",
"APIDefinition.GraphQL.Proxy.SubscriptionType",
"APIDefinition.GraphQL.Proxy.RequestHeaders[0]",
Expand Down
8 changes: 8 additions & 0 deletions apidef/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,14 @@ const Schema = `{
"proxy": {
"type": ["object", "null"],
"properties": {
"features": {
"type": ["object", "null"],
"properties": {
"use_immutable_headers": {
"type": "boolean"
}
}
},
"auth_headers": {
"type": ["object", "null"]
},
Expand Down

0 comments on commit e1ea94a

Please sign in to comment.