private static RuntimeTypeDirective?GetDirectiveValue( HotChocolate.Language.IHasDirectives hasDirectives, NameString directiveName) { DirectiveNode?directive = hasDirectives.Directives.FirstOrDefault( t => directiveName.Equals(t.Name.Value)); if (directive is { Arguments : { Count : > 0 } })
private ICodeDescriptor GenerateObjectSelectionSet( OperationDefinitionNode operation, ObjectType objectType, IType fieldType, WithDirectives fieldOrOperation, FieldCollectionResult typeCase, Path path) { IFragmentNode returnType = HoistFragment( objectType, typeCase.SelectionSet, typeCase.Fragments); IReadOnlyList <IFragmentNode> fragments; string className; if (returnType is null) { fragments = typeCase.Fragments; className = CreateName(fieldOrOperation, objectType, GetClassName); } else { fragments = returnType.Children; className = CreateName(GetClassName(returnType.Fragment.Name)); } var modelSelectionSet = new SelectionSetNode( typeCase.Fields.Select(t => t.Selection).ToList()); var modelFragment = new FragmentNode(new Fragment( className, objectType, modelSelectionSet)); modelFragment.Children.AddRange(fragments); IInterfaceDescriptor modelInterface = CreateInterface(modelFragment, path); var modelClass = new ClassDescriptor( className, _namespace, typeCase.Type, modelInterface); RegisterDescriptor(modelInterface); RegisterDescriptor(modelClass); RegisterDescriptor( new ResultParserMethodDescriptor( GetPathName(path), operation, fieldType, fieldOrOperation as FieldNode, path, modelInterface, new[] { new ResultParserTypeDescriptor(modelClass) })); return(modelInterface); }
public static void AddDirectives( IHasDirectiveDefinition owner, HotChocolate.Language.IHasDirectives ownerSyntax) { foreach (DirectiveNode directive in ownerSyntax.Directives) { if (!directive.IsDeprecationReason() && !directive.IsBindingDirective()) { owner.Directives.Add(new(directive)); } } }
private string CreateName( WithDirectives withDirectives, IType returnType, Func <string, string> nameFormatter) { if (TryGetTypeName(withDirectives, out string typeName)) { return(CreateName(nameFormatter(typeName))); } else if (withDirectives is OperationDefinitionNode operation) { return(CreateName(nameFormatter(operation.Name.Value))); } return(CreateName(nameFormatter(returnType.NamedType().Name))); }
private bool TryGetTypeName( WithDirectives withDirectives, out string typeName) { DirectiveNode directive = withDirectives.Directives.FirstOrDefault(t => t.Name.Value.EqualsOrdinal(GeneratorDirectives.Type)); if (directive is null) { typeName = null; return(false); } typeName = (string)directive.Arguments.Single(a => a.Name.Value.EqualsOrdinal("name")).Value.Value; return(true); }
private static RuntimeTypeDirective?GetSerializationType( HotChocolate.Language.IHasDirectives hasDirectives) => GetDirectiveValue(hasDirectives, "serializationType");
private static RuntimeTypeDirective?GetRuntimeType( HotChocolate.Language.IHasDirectives hasDirectives) => GetDirectiveValue(hasDirectives, "runtimeType");