Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce GraphQL Normalizer #234

Open
ostridm opened this issue Mar 27, 2024 · 0 comments
Open

Introduce GraphQL Normalizer #234

ostridm opened this issue Mar 27, 2024 · 0 comments
Assignees
Labels
Type: enhancement New feature or request.

Comments

@ostridm
Copy link
Contributor

ostridm commented Mar 27, 2024

When working with GraphQL documents, it's essential to ensure that the structure conforms to a normalized format to prevent inconsistencies and improve compatibility with various tools and libraries.

Proposed solution

Implement a GraphQLNormalizer in @har-sdk/core package, make sure the GraphQLImporter executes normalization upon successful deserialisation of an introspection query or conversion of SDL schema.

Considerations

  • Use the IntrospectionQuery type definitions as a reference.
  • Ensure the non-optional properties are present in case the properties format are obvious, e.g.
    • Normalizing the kind property for query, mutation, and subscription types to 'OBJECT' if they are not already specified
    • Normalizing the structure of directives and types (including object types, interface types, union types, and input object types), fields, interfaces, possible types, input fields, and arguments by ensuring the unexpected null arrays are superseded with empty ones

Expected results

The GraphQL normalizer, given a non-compliant document, should normalize it as follows:

{
  url: 'https://example.com/graphql',
  data: {
    __schema: {
      description: null,
      queryType: {
---     name: 'Query'
+++     name: 'Query',
+++     type: 'OBJECT' 
      },
      mutationType: null,
      subscriptionType: null,
      types: [
        {
          kind: 'OBJECT',
          name: 'Foo',
          description: null,
          specifiedByURL: null,
          fields: [
            {
              name: 'bar',
              description: null,
---           args: null,
+++           args: [],
              type: {
                kind: 'NON_NULL',
                name: null,
                ofType: {
                  kind: 'SCALAR',
                  name: 'String',
                  ofType: null
                }
              },
              isDeprecated: false,
              deprecationReason: null
            }
          ],
          inputFields: null,
---       interfaces: null,
+++       interfaces: [],
          enumValues: null,
          possibleTypes: null
        }
      ]
    }
  }
}
@ostridm ostridm added the Type: enhancement New feature or request. label Mar 27, 2024
@ostridm ostridm self-assigned this Mar 27, 2024
ostridm added a commit that referenced this issue Mar 28, 2024
ostridm added a commit that referenced this issue Mar 28, 2024
ostridm added a commit that referenced this issue Mar 28, 2024
@ostridm ostridm changed the title Introduce GraphQL normalizer Introduce GraphQL Normalizer Mar 28, 2024
ostridm added a commit that referenced this issue Mar 28, 2024
ostridm added a commit that referenced this issue Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant