Skip to content

add features section to graphql proxy config#6298

Merged
pvormste merged 4 commits into
masterfrom
feat/TT-11998/add-graphql-proxy-features-section
May 23, 2024
Merged

add features section to graphql proxy config#6298
pvormste merged 4 commits into
masterfrom
feat/TT-11998/add-graphql-proxy-features-section

Conversation

@pvormste

@pvormste pvormste commented May 22, 2024

Copy link
Copy Markdown
Collaborator

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

  • Bug fix (non-breaking change which fixes an issue)
  • 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 📝

Relevant files
Enhancement
api_definitions.go
Add features section to GraphQL proxy configuration.         

apidef/api_definitions.go

  • Added features section to GraphQLProxyConfig.
  • Introduced GraphQLProxyFeaturesConfig struct with UseImmutableHeaders
    field.
  • Updated DummyAPI function to include default features configuration.
  • +10/-0   
    schema.go
    Update GraphQL proxy schema with features section.             

    apidef/schema.go

  • Added features section to GraphQL proxy schema.
  • Included use_immutable_headers property in the schema.
  • +8/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @github-actions

    github-actions Bot commented May 22, 2024

    Copy link
    Copy Markdown
    Contributor

    API Changes

    --- prev.txt	2024-05-23 11:42:05.740327911 +0000
    +++ current.txt	2024-05-23 11:42:02.488344169 +0000
    @@ -733,6 +733,14 @@
                     "proxy": {
                         "type": ["object", "null"],
                         "properties": {
    +						"features": {
    +							"type": ["object", "null"],
    +							"properties": {
    +								"use_immutable_headers": {
    +									"type": "boolean"
    +								}
    +							}
    +						},
                             "auth_headers": {
                                 "type": ["object", "null"]
                             },
    @@ -1358,6 +1366,7 @@
         which will be hosted alongside the api.
     
     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"`
    @@ -1365,6 +1374,10 @@
     	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 GraphQLResponseExtensions struct {
     	OnErrorForwarding bool `bson:"on_error_forwarding" json:"on_error_forwarding"`
     }

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and localized to specific sections of the configuration files. The PR introduces a new feature without altering existing functionalities, which simplifies the review process.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Possible Bug: The new features section in the GraphQLProxyConfig struct is not validated anywhere. This could lead to runtime errors if incorrect data is provided.

    🔒 Security concerns

    No

    Code feedback:
    relevant fileapidef/api_definitions.go
    suggestion      

    Consider adding validation for the GraphQLProxyFeaturesConfig fields to ensure that the configuration provided is correct and to prevent runtime issues. [important]

    relevant lineFeatures GraphQLProxyFeaturesConfig `bson:"features" json:"features"`

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Documentation
    Enhance schema documentation by adding descriptions to the fields

    Add a description to the features and use_immutable_headers fields in the JSON schema to
    improve clarity and documentation for API consumers.

    apidef/schema.go [644-650]

     "features": {
         "type": ["object", "null"],
    +    "description": "Configurable features for the GraphQL proxy.",
         "properties": {
             "use_immutable_headers": {
    -            "type": "boolean"
    +            "type": "boolean",
    +            "description": "Whether to use immutable headers in the proxy."
             }
         }
     }
     
    Suggestion importance[1-10]: 9

    Why: Enhancing schema documentation with descriptions improves clarity for API consumers and aids in understanding the purpose and usage of the fields, which is highly beneficial for maintainability and usability.

    9
    Enhancement
    Add omitempty to the Features field to optimize payload size

    Consider adding omitempty to the Features field in the GraphQLProxyConfig struct to avoid
    serialization of the field if it is empty. This can reduce the payload size when the
    feature is not used.

    apidef/api_definitions.go [852]

    -Features              GraphQLProxyFeaturesConfig             `bson:"features" json:"features"`
    +Features              GraphQLProxyFeaturesConfig             `bson:"features,omitempty" json:"features,omitempty"`
     
    Suggestion importance[1-10]: 8

    Why: This suggestion is beneficial for optimizing payload size by preventing the serialization of empty fields, which can improve performance and reduce data transfer costs.

    8
    Best practice
    Ensure consistent behavior by setting a default value for UseImmutableHeaders

    Add a default value for UseImmutableHeaders in the GraphQLProxyFeaturesConfig struct to
    ensure consistent behavior when the field is not explicitly set.

    apidef/api_definitions.go [861]

    -UseImmutableHeaders bool `bson:"use_immutable_headers" json:"use_immutable_headers"`
    +UseImmutableHeaders bool `bson:"use_immutable_headers" json:"use_immutable_headers" default:"false"`
     
    Suggestion importance[1-10]: 7

    Why: Setting a default value ensures consistent behavior and can prevent potential bugs due to uninitialized fields. However, it is not critical if the application logic already handles default values appropriately.

    7
    Add validation tags to enforce data integrity in GraphQLProxyFeaturesConfig

    Add validation tags to the GraphQLProxyFeaturesConfig struct to enforce data integrity,
    such as ensuring UseImmutableHeaders is not set to an unintended value.

    apidef/api_definitions.go [861]

    -UseImmutableHeaders bool `bson:"use_immutable_headers" json:"use_immutable_headers"`
    +UseImmutableHeaders bool `bson:"use_immutable_headers" json:"use_immutable_headers" validate:"required"`
     
    Suggestion importance[1-10]: 6

    Why: Adding validation tags can help enforce data integrity and prevent unintended values, which is a good practice. However, the necessity depends on the context and existing validation mechanisms in the application.

    6

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @pvormste
    pvormste force-pushed the feat/TT-11998/add-graphql-proxy-features-section branch from 2e1d24f to 09e0d8d Compare May 23, 2024 08:32
    @pvormste
    pvormste enabled auto-merge (squash) May 23, 2024 08:33
    @github-actions

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @sonarqubecloud

    Copy link
    Copy Markdown

    Quality Gate Failed Quality Gate failed

    Failed conditions
    C Reliability Rating on New Code (required ≥ A)

    See analysis details on SonarCloud

    Catch issues before they fail your Quality Gate with our IDE extension SonarLint

    @pvormste
    pvormste merged commit e1ea94a into master May 23, 2024
    @pvormste
    pvormste deleted the feat/TT-11998/add-graphql-proxy-features-section branch May 23, 2024 12:01
    nerdydread pushed a commit that referenced this pull request Sep 6, 2024
    ### **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
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants