Skip to content

Conversation

@seantleonard
Copy link
Contributor

@seantleonard seantleonard commented Jan 26, 2023

Why make this change?

What is this change?

  • Properly generates a GraphQL schema's Query and Mutation fields with the proper mappings as defined in the runtime configuration.
  • Converts an "Exposed" field value to the backing database column name for use in SqlQueryStructures, SqlQueryEngine, and SqlMutationEngine

How was this tested?

In progress.

  • Integration Tests -> Added Mutation, Query (find one, find many, variables, filters) tests for MSSQL, PGSQL, and MySQL
  • Unit Tests -> Added SchemaConverter Unit test to validate that an Entity object's mapping configuration is utilized in the schema generator by checking that mapped column values are used for field names instead of backing column names. Also fixed configuration files for some entities which were not being used in GraphQL tests whose mappings were still incompatible with GraphQL naming requirements (Special language characters, spaces etc.).

Sample Request(s)

Database Column: "__typename" Alias used: "ExclusiveTypeName"

query testQuery {
  myAliasedEntities {
    items {
      conformingName,
      ExclusiveTypeName
    }
  }
}
mutation testMutation {
  createMyAliasedEntity(item: {ExclusiveTypeName: 98, conformingName: "Evie"}) {
    ExclusiveTypeName,
    conformingName
  }
}
mutation testUpdateMutation {
  updateMyAliasedEntity (ExclusiveTypeName: 97, item: {conformingName: "Johan"}){
    ExclusiveTypeName,
    conformingName
  }
}
mutation testDeleteMutation {
  deleteMyAliasedEntity (ExclusiveTypeName: 98){
    ExclusiveTypeName,
    conformingName
  }
}

Sample Runtime Configuration "entities" section

  "entities": {
    "MyAliasedEntity": {
      "source": "graphql_incompatible",
      "rest": false,
      "graphql": true,
      "permissions": [
        {
          "role": "anonymous",
          "actions": [ "create", "read", "update", "delete" ]
        },
        {
          "role": "authenticated",
          "actions": [ "create", "read", "update", "delete" ]
        }
      ],
      "mappings": {
        "__typeName": "ExclusiveTypeName"
      }
    }
  }

@seantleonard seantleonard enabled auto-merge (squash) January 30, 2023 17:53
@Aniruddh25
Copy link
Collaborator

nit: fix PR description - tests have now been added.

Copy link
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an important change missing to add mappings functionality for a long time. Thanks for picking it up this milestone on top of doing the stored proc work!

@seantleonard seantleonard merged commit c49756b into main Jan 30, 2023
@seantleonard seantleonard deleted the dev/seleonar/graphQL_Mappings branch January 30, 2023 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sql: Field Mappings specified in the runtime config are used to provide different GraphQL field names

4 participants