-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
MutationConventionTypeInterceptor.cs
760 lines (640 loc) · 27.2 KB
/
MutationConventionTypeInterceptor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
using System.Linq;
using static HotChocolate.WellKnownMiddleware;
using static HotChocolate.Types.Descriptors.TypeReference;
using static HotChocolate.Resolvers.FieldClassMiddlewareFactory;
using static HotChocolate.Types.ErrorContextDataKeys;
using static HotChocolate.Types.ThrowHelper;
using static HotChocolate.Utilities.ThrowHelper;
using static HotChocolate.WellKnownContextData;
#nullable enable
namespace HotChocolate.Types;
internal sealed class MutationConventionTypeInterceptor : TypeInterceptor
{
private readonly HashSet<Type> _handled = new();
private readonly List<ErrorDefinition> _tempErrors = new();
private TypeInitializer _typeInitializer = default!;
private TypeRegistry _typeRegistry = default!;
private TypeLookup _typeLookup = default!;
private IDescriptorContext _context = default!;
private List<MutationContextData> _mutations = default!;
private ITypeCompletionContext _completionContext = default!;
private TypeReference? _errorInterfaceTypeRef;
private ObjectTypeDefinition? _mutationTypeDef;
private FieldMiddlewareDefinition? _errorNullMiddleware;
internal override void InitializeContext(
IDescriptorContext context,
TypeInitializer typeInitializer,
TypeRegistry typeRegistry,
TypeLookup typeLookup,
TypeReferenceResolver typeReferenceResolver)
{
_context = context;
_typeInitializer = typeInitializer;
_typeRegistry = typeRegistry;
_typeLookup = typeLookup;
}
public override void OnBeforeRegisterDependencies(
ITypeDiscoveryContext discoveryContext,
DefinitionBase definition)
{
// first we need to get a handle on the error interface.
_errorInterfaceTypeRef ??= CreateErrorTypeRef(discoveryContext);
// we will use the error interface and implement it with each error type.
if (definition is ObjectTypeDefinition objectTypeDef)
{
TryAddErrorInterface(objectTypeDef, _errorInterfaceTypeRef);
}
}
public override void OnAfterCompleteTypeNames()
=> _mutations = _context.ContextData.GetMutationFields();
internal override void OnAfterResolveRootType(
ITypeCompletionContext completionContext,
DefinitionBase? definition,
OperationType operationType)
{
// if the type initialization resolved the root type we will capture its definition
// so we can use it after the type extensions are merged into this type.
if (operationType is OperationType.Mutation)
{
_mutationTypeDef = (ObjectTypeDefinition)definition!;
}
// we need to capture a completion context to resolve types.
// any context will do.
_completionContext ??= completionContext;
}
public override void OnAfterMergeTypeExtensions()
{
// if we have found a mutation type we will start applying the mutation conventions
// on the mutations.
if (_mutationTypeDef is not null)
{
HashSet<MutationContextData> unprocessed = new(_mutations);
var defLookup = _mutations.ToDictionary(t => t.Definition);
var nameLookup = _mutations.ToDictionary(t => t.Name);
var rootOptions = CreateOptions(_context.ContextData);
foreach (var mutationField in _mutationTypeDef.Fields)
{
if (mutationField.IsIntrospectionField)
{
// we skip over any introspection fields like `__typename`
continue;
}
var mutationOptions = rootOptions;
// if the mutation has any error attributes we will interpret that as an opt-in
// to the mutation conventions.
if (mutationField.ContextData.ContainsKey(ErrorDefinitions) &&
!mutationOptions.Apply)
{
mutationOptions = CreateErrorOptions(mutationOptions);
}
// next we check for specific mutation configuration overrides.
// if a user provided specific mutation settings they will take
// precedence over global and inferred settings.
if (defLookup.TryGetValue(mutationField, out var cd) ||
nameLookup.TryGetValue(mutationField.Name, out cd))
{
mutationOptions = CreateOptions(cd, mutationOptions);
unprocessed.Remove(cd);
}
if (mutationOptions.Apply)
{
// if the mutation options indicate that we shall apply the mutation
// conventions we will start rewriting the field.
ApplyResultMiddleware(mutationField);
TryApplyInputConvention(mutationField, mutationOptions);
TryApplyPayloadConvention(mutationField, cd?.PayloadFieldName, mutationOptions);
}
}
if (unprocessed.Count > 0)
{
throw NonMutationFields(unprocessed);
}
}
}
private static void ApplyResultMiddleware(ObjectFieldDefinition mutation)
{
var middlewareDef = new FieldMiddlewareDefinition(
next => async context =>
{
await next(context).ConfigureAwait(false);
if (context.Result is IMutationResult result)
{
// by checking if it is not an error we can accept the default
// value of the struct as null.
if (!result.IsError)
{
context.Result = result.Value;
}
else
{
context.SetScopedState(Errors, result.Value);
context.Result = MarkerObjects.ErrorObject;
}
}
// we will replace null with our null marker object so
// that
context.Result ??= MarkerObjects.Null;
},
isRepeatable: false,
key: MutationResult);
mutation.MiddlewareDefinitions.Insert(0, middlewareDef);
}
private void TryApplyInputConvention(ObjectFieldDefinition mutation, Options options)
{
if (mutation.Arguments.Count is 0)
{
return;
}
var inputTypeName = options.FormatInputTypeName(mutation.Name);
if (_typeRegistry.NameRefs.ContainsKey(inputTypeName))
{
return;
}
var inputType = CreateInputType(inputTypeName, mutation);
RegisterType(inputType);
var resolverArguments = new List<ResolverArgument>();
foreach (var argument in mutation.Arguments)
{
var runtimeType = argument.RuntimeType ??
argument.Parameter?.ParameterType ??
typeof(object);
var formatter =
argument.Formatters.Count switch
{
0 => null,
1 => argument.Formatters[0],
_ => new AggregateInputValueFormatter(argument.Formatters)
};
resolverArguments.Add(
new ResolverArgument(
argument.Name,
new FieldCoordinate(inputTypeName, argument.Name),
_completionContext.GetType<IInputType>(argument.Type!),
runtimeType,
argument.DefaultValue,
formatter));
}
var argumentMiddleware =
new FieldMiddlewareDefinition(
Create<MutationConventionMiddleware>(
(typeof(string), options.InputArgumentName),
(typeof(IReadOnlyList<ResolverArgument>), resolverArguments)),
key: MutationArguments,
isRepeatable: false);
mutation.Arguments.Clear();
mutation.Arguments.Add(new(options.InputArgumentName, type: Parse($"{inputTypeName}!")));
mutation.MiddlewareDefinitions.Insert(0, argumentMiddleware);
}
private void TryApplyPayloadConvention(
ObjectFieldDefinition mutation,
string? payloadFieldName,
Options options)
{
var typeRef = mutation.Type;
var payloadTypeName = options.FormatPayloadTypeName(mutation.Name);
// we ensure that we can resolve the mutation result type.
if (!_typeLookup.TryNormalizeReference(typeRef!, out typeRef) ||
!_typeRegistry.TryGetType(typeRef, out var registration))
{
throw CannotResolvePayloadType();
}
// before starting to build the payload type we first will look for error definitions
// an the mutation.
var errorDefinitions = GetErrorDefinitions(mutation);
FieldDef? errorField = null;
// if the mutation result type matches the payload type name pattern
// we expect it to be already a proper payload and will not transform the
// result type to a payload. However, we will check if we need to add the
// errors field to it.
if (registration.Type.Name.EqualsOrdinal(payloadTypeName))
{
if (errorDefinitions.Count <= 0)
{
return;
}
// first we retrieve the payload type that was defined by the user.
var payloadType = _completionContext.GetType<IType>(typeRef);
// we ensure that the payload type is an object type; otherwise we raise an error.
if (payloadType.IsListType() || payloadType.NamedType() is not ObjectType obj)
{
_completionContext.ReportError(
MutationPayloadMustBeObject(payloadType.NamedType()));
return;
}
// we grab the definition to mutate the payload type.
var payloadTypeDef = obj.Definition!;
// next we create a null middleware which will return null for any payload
// field that we have on the payload type if a mutation error was returned.
var nullMiddleware = _errorNullMiddleware ??=
new FieldMiddlewareDefinition(
Create<ErrorNullMiddleware>(),
key: MutationErrorNull,
isRepeatable: false);
foreach (var resultField in payloadTypeDef.Fields)
{
// if the field is the query mutation field we will allow it to stay non-nullable
// since it does not need the parent.
if (resultField.Type is null || resultField.CustomSettingExists(MutationQueryField))
{
continue;
}
// first we ensure that all fields on the mutation payload are nullable.
resultField.Type = EnsureNullable(resultField.Type);
// next we will add the null middleware as the first middleware element
resultField.MiddlewareDefinitions.Insert(0, nullMiddleware);
}
// We will ensure that the mutation return value is actually not nullable.
// If there was an actual GraphQL error on the mutation it ensures that
// the next mutation execution is aborted.
//
// mutation {
// currentMutationThatErrors <---
// nextMutationWillNotBeInvoked
// }
//
// Mutations are executed sequentially and by having the payload
// non-nullable the complete result is erased (non-null propagation)
// which causes the execution to stop.
mutation.Type = EnsureNonNull(mutation.Type!);
// now that everything is put in place we will create the error types and
// the error middleware.
var errorTypeName = options.FormatErrorTypeName(mutation.Name);
RegisterErrorType(CreateErrorType(errorTypeName, errorDefinitions), mutation.Name);
var errorListTypeRef = Parse($"[{errorTypeName}!]");
payloadTypeDef.Fields.Add(
new ObjectFieldDefinition(
options.PayloadErrorsFieldName,
type: errorListTypeRef,
resolver: ctx =>
{
ctx.ScopedContextData.TryGetValue(Errors, out var errors);
return new ValueTask<object?>(errors);
}));
// collect error factories for middleware
var errorFactories = errorDefinitions.Select(t => t.Factory).ToArray();
// create middleware
var errorMiddleware =
new FieldMiddlewareDefinition(
Create<ErrorMiddleware>(
(typeof(IReadOnlyList<CreateError>), errorFactories)),
key: MutationErrors,
isRepeatable: false);
// last but not least we insert the error middleware to the mutation field.
mutation.MiddlewareDefinitions.Insert(0, errorMiddleware);
// we return here since we handled the case where the user has provided a custom
// payload type.
return;
}
// if this mutation has error definitions we will create the error middleware,
// the payload error type and the error field definition that will be exposed
// on the payload.
if (errorDefinitions.Count > 0)
{
// create error type
var errorTypeName = options.FormatErrorTypeName(mutation.Name);
RegisterErrorType(CreateErrorType(errorTypeName, errorDefinitions), mutation.Name);
var errorListTypeRef = Parse($"[{errorTypeName}!]");
errorField = new FieldDef(options.PayloadErrorsFieldName, errorListTypeRef);
// collect error factories for middleware
var errorFactories = errorDefinitions.Select(t => t.Factory).ToArray();
// create middleware
var errorMiddleware =
new FieldMiddlewareDefinition(
Create<ErrorMiddleware>(
(typeof(IReadOnlyList<CreateError>), errorFactories)),
key: MutationErrors,
isRepeatable: false);
mutation.MiddlewareDefinitions.Insert(0, errorMiddleware);
}
// lastly we will create the mutation payload and replace with it the current mutation
// result type.
payloadFieldName ??= _context.Naming.FormatFieldName(registration.Type.Name);
var type = CreatePayloadType(
payloadTypeName,
new(payloadFieldName, EnsureNullable(mutation.Type!)),
errorField);
RegisterType(type);
mutation.Type = Parse($"{payloadTypeName}!");
// we mustn't forget to drop the error definitions at this point since we do not
// want to preserve them on the actual schema field.
mutation.ContextData.Remove(ErrorDefinitions);
}
private static InputObjectType CreateInputType(
string typeName,
ObjectFieldDefinition fieldDef)
{
var inputObjectDef = new InputObjectTypeDefinition(typeName);
foreach (var argumentDef in fieldDef.Arguments)
{
var inputFieldDef = new InputFieldDefinition();
argumentDef.CopyTo(inputFieldDef);
inputFieldDef.RuntimeType =
argumentDef.RuntimeType ??
argumentDef.Parameter?.ParameterType;
inputObjectDef.Fields.Add(inputFieldDef);
}
return InputObjectType.CreateUnsafe(inputObjectDef);
}
private static ObjectType CreatePayloadType(
string typeName,
FieldDef data,
FieldDef? error)
{
var objectDef = new ObjectTypeDefinition(typeName);
var dataFieldDef = new ObjectFieldDefinition(
data.Name,
type: data.Type,
pureResolver: ctx =>
{
var parent = ctx.Parent<object?>();
if (ReferenceEquals(MarkerObjects.ErrorObject, parent) ||
ReferenceEquals(MarkerObjects.Null, parent))
{
return null;
}
return parent;
});
objectDef.Fields.Add(dataFieldDef);
// if the mutation has domain errors we will add the errors
// field to the payload type.
if (error is not null)
{
var errorFieldDef = new ObjectFieldDefinition(
error.Value.Name,
type: error.Value.Type,
resolver: ctx =>
{
ctx.ScopedContextData.TryGetValue(Errors, out var errors);
return new ValueTask<object?>(errors);
});
objectDef.Fields.Add(errorFieldDef);
}
return ObjectType.CreateUnsafe(objectDef);
}
private UnionType CreateErrorType(
string typeName,
IReadOnlyList<ErrorDefinition> errorDefinitions)
{
var unionDef = new UnionTypeDefinition(typeName);
foreach (var error in errorDefinitions)
{
unionDef.Types.Add(_context.TypeInspector.GetOutputTypeRef(error.SchemaType));
}
return UnionType.CreateUnsafe(unionDef);
}
private static TypeReference CreateErrorTypeRef(ITypeDiscoveryContext context)
=> CreateErrorTypeRef(context.DescriptorContext);
private static TypeReference CreateErrorTypeRef(IDescriptorContext context)
{
var errorInterfaceType =
context.ContextData.TryGetValue(ErrorType, out var value) &&
value is Type type
? type
: typeof(ErrorInterfaceType);
if (!context.TypeInspector.IsSchemaType(errorInterfaceType))
{
errorInterfaceType = typeof(InterfaceType<>).MakeGenericType(errorInterfaceType);
}
return context.TypeInspector.GetOutputTypeRef(errorInterfaceType);
}
private static void TryAddErrorInterface(
ObjectTypeDefinition objectTypeDef,
TypeReference errorInterfaceTypeRef)
{
if (objectTypeDef.ContextData.IsError())
{
objectTypeDef.Interfaces.Add(errorInterfaceTypeRef);
}
}
private IReadOnlyList<ErrorDefinition> GetErrorDefinitions(
ObjectFieldDefinition mutation)
{
var errorTypes = GetErrorResultTypes(mutation);
if (mutation.ContextData.TryGetValue(ErrorDefinitions, out var value) &&
value is IReadOnlyList<ErrorDefinition> errorDefs)
{
if (errorTypes.Length == 0)
{
return errorDefs;
}
_handled.Clear();
_tempErrors.Clear();
foreach (var errorDef in errorDefs)
{
_handled.Add(errorDef.RuntimeType);
_tempErrors.Add(errorDef);
}
CreateErrorDefinitions(errorTypes, _handled, _tempErrors);
return _tempErrors.ToArray();
}
if (errorTypes.Length > 0)
{
_handled.Clear();
_tempErrors.Clear();
CreateErrorDefinitions(errorTypes, _handled, _tempErrors);
return _tempErrors.ToArray();
}
return Array.Empty<ErrorDefinition>();
// ReSharper disable once VariableHidesOuterVariable
static void CreateErrorDefinitions(
Type[] errorTypes,
HashSet<Type> handled,
List<ErrorDefinition> tempErrors)
{
foreach (var errorType in errorTypes)
{
if (handled.Add(errorType))
{
if (typeof(Exception).IsAssignableFrom(errorType))
{
var schemaType = typeof(ExceptionObjectType<>).MakeGenericType(errorType);
var definition = new ErrorDefinition(
errorType,
schemaType,
ex => ex.GetType() == errorType
? ex
: null);
tempErrors.Add(definition);
}
else
{
var schemaType = typeof(ErrorObjectType<>).MakeGenericType(errorType);
var definition = new ErrorDefinition(
errorType,
schemaType,
obj => obj);
tempErrors.Add(definition);
}
}
}
}
}
private static Type[] GetErrorResultTypes(ObjectFieldDefinition mutation)
{
var resultType = mutation.ResultType;
if (resultType?.IsGenericType ?? false)
{
var typeDefinition = resultType.GetGenericTypeDefinition();
if (typeDefinition == typeof(Task<>) || typeDefinition == typeof(ValueTask<>))
{
resultType = resultType.GenericTypeArguments[0];
}
}
if (resultType is { IsValueType: true, IsGenericType: true } &&
typeof(IMutationResult).IsAssignableFrom(resultType))
{
var types = resultType.GenericTypeArguments;
if (types.Length > 1)
{
var errorTypes = new Type[types.Length - 1];
for (var i = 1; i < types.Length; i++)
{
errorTypes[i - 1] = types[i];
}
return errorTypes;
}
}
return Array.Empty<Type>();
}
private static Options CreateOptions(
IDictionary<string, object?> contextData)
{
if (contextData.TryGetValue(MutationContextDataKeys.Options, out var value) &&
value is MutationConventionOptions options)
{
return new Options(
options.InputTypeNamePattern,
options.InputArgumentName,
options.PayloadTypeNamePattern,
options.PayloadErrorTypeNamePattern,
options.PayloadErrorsFieldName,
options.ApplyToAllMutations);
}
return new Options(null, null, null, null, null, null);
}
private static Options CreateOptions(
MutationContextData contextData,
Options parent = default)
{
return new Options(
contextData.InputTypeName ?? parent.InputTypeNamePattern,
contextData.InputArgumentName ?? parent.InputArgumentName,
contextData.PayloadTypeName ?? parent.PayloadTypeNamePattern,
contextData.PayloadPayloadErrorTypeName ?? parent.PayloadErrorTypeNamePattern,
contextData.PayloadErrorsFieldName ?? parent.PayloadErrorsFieldName,
contextData.Enabled);
}
private static Options CreateErrorOptions(
Options parent = default)
{
return new Options(
parent.InputTypeNamePattern,
parent.InputArgumentName,
parent.PayloadTypeNamePattern,
parent.PayloadErrorTypeNamePattern,
parent.PayloadErrorsFieldName,
true);
}
private void RegisterType(TypeSystemObjectBase type)
{
var registeredType = _typeInitializer.InitializeType(type);
_typeInitializer.CompleteTypeName(registeredType);
}
private void RegisterErrorType(
TypeSystemObjectBase type,
string mutationName)
{
try
{
var registeredType = _typeInitializer.InitializeType(type);
_typeInitializer.CompleteTypeName(registeredType);
}
catch (SchemaException ex)
when (ex.Errors[0].Code.EqualsOrdinal(ErrorCodes.Schema.DuplicateTypeName))
{
throw TypeInitializer_MutationDuplicateErrorName(
type,
mutationName,
type.Name,
ex.Errors);
}
}
private TypeReference EnsureNullable(TypeReference typeRef)
{
var type = _completionContext.GetType<IType>(typeRef);
if (type is not NonNullType nt)
{
return typeRef;
}
return Create(CreateTypeNode(nt.Type));
}
private TypeReference EnsureNonNull(TypeReference typeRef)
{
var type = _completionContext.GetType<IType>(typeRef);
if (type.Kind is TypeKind.NonNull)
{
return typeRef;
}
return Create(CreateTypeNode(new NonNullType(type)));
}
private ITypeNode CreateTypeNode(IType type)
=> type switch
{
NonNullType nnt => new NonNullTypeNode((INullableTypeNode)CreateTypeNode(nnt.Type)),
ListType lt => new ListTypeNode(CreateTypeNode(lt.ElementType)),
INamedType nt => new NamedTypeNode(nt.Name),
_ => throw new NotSupportedException("Type is not supported.")
};
private readonly ref struct Options
{
public Options(
string? inputTypeNamePattern,
string? inputArgumentName,
string? payloadTypeNamePattern,
string? payloadErrorTypeNamePattern,
string? payloadErrorsFieldName,
bool? apply)
{
InputTypeNamePattern = inputTypeNamePattern ??
MutationConventionOptionDefaults.InputTypeNamePattern;
InputArgumentName = inputArgumentName ??
MutationConventionOptionDefaults.InputArgumentName;
PayloadTypeNamePattern = payloadTypeNamePattern ??
MutationConventionOptionDefaults.PayloadTypeNamePattern;
PayloadErrorsFieldName = payloadErrorsFieldName ??
MutationConventionOptionDefaults.PayloadErrorsFieldName;
PayloadErrorTypeNamePattern = payloadErrorTypeNamePattern ??
MutationConventionOptionDefaults.ErrorTypeNamePattern;
Apply = apply ??
MutationConventionOptionDefaults.ApplyToAllMutations;
}
public string InputTypeNamePattern { get; }
public string InputArgumentName { get; }
public string PayloadTypeNamePattern { get; }
public string PayloadErrorTypeNamePattern { get; }
public string PayloadErrorsFieldName { get; }
public bool Apply { get; }
public string FormatInputTypeName(string mutationName)
=> InputTypeNamePattern.Replace(
$"{{{MutationConventionOptionDefaults.MutationName}}}",
char.ToUpper(mutationName[0]) + mutationName.Substring(1));
public string FormatPayloadTypeName(string mutationName)
=> PayloadTypeNamePattern.Replace(
$"{{{MutationConventionOptionDefaults.MutationName}}}",
char.ToUpper(mutationName[0]) + mutationName.Substring(1));
public string FormatErrorTypeName(string mutationName)
=> PayloadErrorTypeNamePattern.Replace(
$"{{{MutationConventionOptionDefaults.MutationName}}}",
char.ToUpper(mutationName[0]) + mutationName.Substring(1));
}
private readonly struct FieldDef
{
public FieldDef(string name, TypeReference type)
{
Name = name;
Type = type;
}
public string Name { get; }
public TypeReference Type { get; }
}
}