Add Input/Output model splitting to GraphQL mutation engine#60
Add Input/Output model splitting to GraphQL mutation engine#60FionaBronwen wants to merge 2 commits intofionabronwen/emitter-integrationfrom
Conversation
b4208ef to
336b711
Compare
d900bb0 to
1bd1b71
Compare
336b711 to
ccc10f6
Compare
1bd1b71 to
0c1ebbc
Compare
ccc10f6 to
9c89a06
Compare
0c1ebbc to
da1b154
Compare
8cd1884 to
c469bda
Compare
64b077f to
50cd3e4
Compare
decde60 to
bcfae7d
Compare
- Update GraphQLMutationOptions with usageFlag and mutationKey - GraphQLModelMutation adds 'Input' suffix for input types - GraphQLMutationEngine.mutateModel() returns ModelMutationResult with separate input/output mutations based on resolveUsages() - ModelTypeMap supports GraphQLInputObjectType for input types - Schema emitter handles both input and output model variants - Add 5 new tests for input/output splitting behavior
50cd3e4 to
56e78bf
Compare
| this.engine = new MutationEngine(tk, graphqlMutationRegistry); | ||
|
|
||
| // Resolve usages once at construction time | ||
| this.usageTracker = resolveUsages(namespace); |
There was a problem hiding this comment.
This is an expensive operation so we probably don't want to do it in the constructor.
Expensive calls can be made lazily; i.e. if we ask for usage information (in getUsage) and we have not yet resolved usages, we do so (and store the result). Callers should also have the flexibility to trigger the resolve explicitly to optimize their call flow.
| */ | ||
| readonly usageFlag: UsageFlags; | ||
|
|
||
| constructor(usageFlag: UsageFlags = UsageFlags.None) { |
There was a problem hiding this comment.
It's valid for me to do
new GraphQLMutationOptions(usageFlag: UsageFlags.Input | UsageFlags.Output);or any other combination of the flags.
So we either need to account for this in mutationKey(), or do an explicit check at construction time that usageFlag is only the values that we expect.
| } | ||
| return this.materializeOutputType(name, tspModel); | ||
| return this.materializeOutputType(tspModel, name); | ||
| } |
There was a problem hiding this comment.
Why do we need to pass the name explicitly here; can't we access the name property on the tspModel in the functions we're calling?
Summary
This PR adds usage-aware model mutations that create separate input and output type variants based on how models are used in operations. This brings the TSP models in line with the GraphQL requirement of separate input and output types.
Changes
GraphQLMutationOptions- AddedusageFlagandmutationKeyfor usage-aware cachingGraphQLModelMutation- Adds "Input" suffix for input typesGraphQLMutationEngine.mutateModel()- ReturnsModelMutationResultwith separate input/output mutationsModelTypeMap- SupportsGraphQLInputObjectTypefor input typesHow it works