private static void CompileMiddleware( ITypeCompletionContext context, ObjectFieldDefinition definition, ITypeReference argumentTypeReference, FieldMiddleware placeholder) { IFilterNamingConvention convention = context.DescriptorContext.GetFilterNamingConvention(); IFilterInputType type = context.GetType <IFilterInputType>(argumentTypeReference); Type middlewareType = _middlewareDefinition.MakeGenericType(type.EntityType); FieldMiddleware middleware = FieldClassMiddlewareFactory.Create(middlewareType, FilterMiddlewareContext.Create(convention.ArgumentName)); int index = definition.MiddlewareComponents.IndexOf(placeholder); definition.MiddlewareComponents[index] = middleware; }
public bool TryGetFieldHandler( ITypeCompletionContext context, ISortInputTypeDefinition typeDefinition, ISortFieldDefinition fieldDefinition, [NotNullWhen(true)] out ISortFieldHandler?handler) { foreach (ISortFieldHandler sortFieldHandler in _provider.FieldHandlers) { if (sortFieldHandler.CanHandle(context, typeDefinition, fieldDefinition)) { handler = sortFieldHandler; return(true); } } handler = null; return(false); }
public static FieldCollection <TField> CompleteFields <TFieldDefinition, TField>( ITypeCompletionContext context, ITypeSystemMember declaringMember, IEnumerable <TFieldDefinition> fieldDefs, Func <TFieldDefinition, int, TField> fieldFactory, int maxFieldCount) where TFieldDefinition : FieldDefinitionBase, IHasSyntaxNode where TField : class, IField { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (declaringMember is null) { throw new ArgumentNullException(nameof(declaringMember)); } if (fieldDefs is null) { throw new ArgumentNullException(nameof(fieldDefs)); } if (fieldFactory is null) { throw new ArgumentNullException(nameof(fieldDefs)); } if (maxFieldCount < 1) { throw new ArgumentOutOfRangeException( paramName: nameof(maxFieldCount), actualValue: maxFieldCount, message: TypeResources.FieldInitHelper_CompleteFields_MaxFieldCountToSmall); } return(CompleteFieldsInternal( context, declaringMember, fieldDefs, fieldFactory, maxFieldCount)); }
public override void OnBeforeCompleteType( ITypeCompletionContext completionContext, DefinitionBase definition, IDictionary <string, object> contextData) { if (definition is ObjectTypeDefinition objectTypeDefinition) { var position = 0; IDescriptorContext context = completionContext.DescriptorContext; if (completionContext.IsQueryType ?? false) { objectTypeDefinition.Fields.Insert(position++, CreateSchemaField(context)); objectTypeDefinition.Fields.Insert(position++, CreateTypeField(context)); } objectTypeDefinition.Fields.Insert(position, CreateTypeNameField(context)); } }
protected override void OnCompleteField( ITypeCompletionContext context, ITypeSystemMember declaringMember, ObjectFieldDefinition definition) { base.OnCompleteField(context, declaringMember, definition); CompleteExecutableDirectives(context); CompleteResolver(context, definition); // going forward we should rework the list detection in the ExtendedType to already // provide us with the info if a type is an async enumerable. if (Type.IsListType() && definition.ResultType is { IsGenericType : true } resultType&& context.TypeInspector.GetType(resultType).Definition == typeof(IAsyncEnumerable <>)) { MaybeStream = true; } }
private static void CompileMiddleware( Type type, ObjectFieldDefinition definition, FieldMiddleware placeholder, ITypeCompletionContext context) { string filterConventionArgumentName = context.DescriptorContext.GetFilterNamingConvention().ArgumentName; string sortingConventionArgumentName = context.DescriptorContext.GetSortingNamingConvention().ArgumentName; Type middlewareType = _middlewareDefinition.MakeGenericType(type); FieldMiddleware middleware = FieldClassMiddlewareFactory.Create(middlewareType, SelectionMiddlewareContext.Create( filterConventionArgumentName, sortingConventionArgumentName)); int index = definition.MiddlewareComponents.IndexOf(placeholder); definition.MiddlewareComponents[index] = middleware; }
internal sealed override void CompleteType(ITypeCompletionContext context) { AssertNamed(); TDefinition definition = _definition !; OnBeforeCompleteType(context, definition, definition.ContextData); ExecuteConfigurations(context, definition, ApplyConfigurationOn.Completion); Description = definition.Description; OnCompleteType(context, definition); _contextData = definition.ContextData; _definition = null; OnAfterCompleteType(context, definition, _contextData); MarkCompleted(); }
public override void OnBeforeCompleteType( ITypeCompletionContext completionContext, DefinitionBase?definition, IDictionary <string, object?> contextData) { if (definition is InputObjectTypeDefinition inputObjectTypeDefinition) { foreach (InputFieldDefinition inputFieldDefinition in inputObjectTypeDefinition.Fields) { (string NodeTypeName, Type IdRuntimeType)? idInfo = GetIdInfo(completionContext, inputFieldDefinition); if (idInfo != null) { InsertFormatter( completionContext, inputFieldDefinition, idInfo.Value.NodeTypeName, idInfo.Value.IdRuntimeType); } } } else if (definition is ObjectTypeDefinition objectTypeDefinition) { foreach (ObjectFieldDefinition objectFieldDefinition in objectTypeDefinition.Fields) { foreach (ArgumentDefinition argumentDefinition in objectFieldDefinition.Arguments) { (string NodeTypeName, Type IdRuntimeType)? idInfo = GetIdInfo(completionContext, argumentDefinition); if (idInfo != null) { InsertFormatter( completionContext, argumentDefinition, idInfo.Value.NodeTypeName, idInfo.Value.IdRuntimeType); } } } } base.OnBeforeCompleteType(completionContext, definition, contextData); }
private bool TryCompleteDirective( ITypeCompletionContext context, DirectiveDefinition definition, ISet <string> processed, [NotNullWhen(true)] out Directive?directive) { if (!context.TryGetDirectiveType( definition.Reference, out DirectiveType? directiveType)) { directive = null; return(false); } if (!processed.Add(directiveType.Name) && !directiveType.IsRepeatable) { context.ReportError( DirectiveCollection_DirectiveIsUnique( directiveType, context.Type, definition.ParsedDirective, _source)); directive = null; return(false); } if (directiveType.Locations.Contains(_location)) { directive = Directive.FromDescription(directiveType, definition, _source); return(true); } context.ReportError( DirectiveCollection_LocationNotAllowed( directiveType, _location, context.Type, definition.ParsedDirective, _source)); directive = null; return(false); }
public override void OnBeforeCompleteType( ITypeCompletionContext completionContext, DefinitionBase?definition, IDictionary <string, object?> contextData) { // when we are visiting the query type we will add the schema definition field. if ((completionContext.IsQueryType ?? false) && definition is ObjectTypeDefinition objectTypeDefinition) { ObjectFieldDefinition typeNameField = objectTypeDefinition.Fields.First( t => t.Name.Equals(IntrospectionFields.TypeName) && t.IsIntrospectionField); var index = objectTypeDefinition.Fields.IndexOf(typeNameField) + 1; var descriptor = ObjectFieldDescriptor.New( completionContext.DescriptorContext, SchemaDefinitionField); descriptor .Argument(ConfigurationArgument, a => a.Type <NonNullType <StringType> >()) .Type <SchemaDefinitionType>() .Resolve(ctx => { string name = ctx.ArgumentValue <string>(ConfigurationArgument); return(ctx.Schema.ContextData .GetSchemaDefinitions() .FirstOrDefault(t => t.Name.Equals(name))); }); objectTypeDefinition.Fields.Insert(index, descriptor.CreateDefinition()); } // when we visit the schema definition we will copy over the schema definition list // that sits on the schema creation context. else if (definition is SchemaTypeDefinition && completionContext.ContextData.TryGetValue( WellKnownContextData.SchemaDefinitions, out object?schemaDefinitions)) { contextData[WellKnownContextData.SchemaDefinitions] = schemaDefinitions; } }
public static void Complete( ITypeCompletionContext context, IComplexOutputTypeDefinition definition, Type clrType, ICollection <InterfaceType> interfaces, ITypeSystemObject interfaceOrObject, ISyntaxNode?node) { if (clrType != typeof(object)) { TryInferInterfaceUsageFromClrType(context, clrType, interfaces); } if (definition.KnownClrTypes.Count > 0) { definition.KnownClrTypes.Remove(typeof(object)); foreach (Type type in definition.KnownClrTypes.Distinct()) { TryInferInterfaceUsageFromClrType(context, type, interfaces); } } foreach (ITypeReference interfaceRef in definition.Interfaces) { if (!context.TryGetType(interfaceRef, out InterfaceType type)) { // TODO : resources context.ReportError(SchemaErrorBuilder.New() .SetMessage("COULD NOT RESOLVE INTERFACE") .SetCode(ErrorCodes.Schema.MissingType) .SetTypeSystemObject(interfaceOrObject) .AddSyntaxNode(node) .Build()); } if (!interfaces.Contains(type)) { interfaces.Add(type); } } }
private static void MergeFilterFieldDefinitions( ITypeCompletionContext context, IList <InputFieldDefinition> extensionFields, IList <InputFieldDefinition> typeFields) { MergeFilterFields( context, extensionFields, typeFields, (fields, extensionField, typeField) => { if (typeField is FilterFieldDefinition filterTypeField && extensionField is FilterFieldDefinition filterExtensionField) { filterTypeField.Handler ??= filterExtensionField.Handler; } typeField.Description ??= extensionField.Description; typeField.RuntimeDefaultValue ??= extensionField.RuntimeDefaultValue; });
public static void OnBeforeCompleteType( ITypeCompletionContext completionContext, DefinitionBase?definition, IDictionary <string, object?> contextData) { if (definition is not ObjectTypeDefinition objectTypeDefinition) { return; } var validationOptions = completionContext.ContextData.GetValidationOptions(); foreach (var objectFieldDefinition in objectTypeDefinition.Fields) { var argumentOptions = objectFieldDefinition.Arguments .Where(argument => argument.ContextData.ShouldValidateArgument()) .Select(argument => argument.ContextData.GetArgumentOptions()) .ToList(); if (argumentOptions is { Count: > 0 })
private static void CompileMiddleware( ITypeCompletionContext context, ObjectFieldDefinition definition, ITypeReference argumentTypeReference, FieldMiddleware placeholder, string?scope) { IFilterInputType type = context.GetType <IFilterInputType>(argumentTypeReference); IFilterConvention convention = context.DescriptorContext.GetFilterConvention(scope); var fieldDescriptor = ObjectFieldDescriptor.From(context.DescriptorContext, definition); convention.ConfigureField(fieldDescriptor); MethodInfo factory = _factoryTemplate.MakeGenericMethod(type.EntityType.Source); var middleware = (FieldMiddleware)factory.Invoke(null, new object[] { convention }) !; var index = definition.MiddlewareComponents.IndexOf(placeholder); definition.MiddlewareComponents[index] = middleware; }
protected override void OnCompleteField( ITypeCompletionContext context, ArgumentDefinition definition) { if (definition.Type is null) { context.ReportError(SchemaErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, TypeResources.Argument_TypeIsNull, definition.Name)) .SetTypeSystemObject(context.Type) .Build()); } else { base.OnCompleteField(context, definition); DefaultValue = FieldInitHelper.CreateDefaultValue(context, definition, Type); } }
private static void CompileMiddleware( Type type, ObjectFieldDefinition definition, FieldMiddleware placeholder, ITypeCompletionContext context, string?scope) { IProjectionConvention convention = context.DescriptorContext.GetProjectionConvention(scope); RegisterOptimizer(definition.ContextData, convention.CreateOptimizer()); definition.ContextData[ProjectionContextIdentifier] = true; MethodInfo factory = _factoryTemplate.MakeGenericMethod(type); var middleware = (FieldMiddleware)factory.Invoke(null, new object[] { convention }) !; var index = definition.MiddlewareComponents.IndexOf(placeholder); definition.MiddlewareComponents[index] = middleware; }
private void MergeValues( ITypeCompletionContext context, EnumTypeDefinition extension, EnumTypeDefinition type) { foreach (EnumValueDefinition enumValue in extension.Values.Where(t => t.Value != null)) { if (type.RuntimeType.IsInstanceOfType(enumValue.Value)) { EnumValueDefinition?existingValue = type.Values.FirstOrDefault(t => enumValue.Value.Equals(t.Value)); if (existingValue is null) { type.Values.Add(enumValue); } else { TypeExtensionHelper.MergeContextData(enumValue, existingValue); TypeExtensionHelper.MergeDirectives( context, enumValue.Directives, existingValue.Directives); } } else { context.ReportError( SchemaErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, TypeResources.EnumTypeExtension_ValueTypeInvalid, enumValue.Value)) .SetTypeSystemObject(this) .Build()); } } }
private static FieldResolverDelegates CompileResolver( ITypeCompletionContext context, ObjectFieldDefinition definition) { FieldResolverDelegates resolvers = definition.Resolvers; if (!resolvers.HasResolvers) { if (definition.Expression is LambdaExpression lambdaExpression) { resolvers = context.DescriptorContext.ResolverCompiler.CompileResolve( lambdaExpression, definition.SourceType ?? definition.Member?.ReflectedType ?? definition.Member?.DeclaringType ?? typeof(object), definition.ResolverType); } else if (definition.ResolverMember is not null) { resolvers = context.DescriptorContext.ResolverCompiler.CompileResolve( definition.ResolverMember, definition.SourceType ?? definition.Member?.ReflectedType ?? definition.Member?.DeclaringType ?? typeof(object), definition.ResolverType); } else if (definition.Member is not null) { resolvers = context.DescriptorContext.ResolverCompiler.CompileResolve( definition.Member, definition.SourceType ?? definition.Member.ReflectedType ?? definition.Member.DeclaringType, definition.ResolverType); } } return(resolvers); }
void ILazyTypeConfiguration.Configure(ITypeCompletionContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (Definition is null) { throw new InvalidOperationException( TypeResources.TypeConfiguration_DefinitionIsNull); } if (Configure is null) { throw new InvalidOperationException( TypeResources.TypeConfiguration_ConfigureIsNull); } Configure(context, Definition); }
protected override void OnCompleteTypeSet( ITypeCompletionContext context, UnionTypeDefinition definition, ISet <ObjectType> typeSet) { base.OnCompleteTypeSet(context, definition, typeSet); Type markerType = definition.RuntimeType; if (markerType != typeof(object)) { foreach (ObjectType type in context.GetTypes <ObjectType>()) { if (type.RuntimeType != typeof(object) && markerType.IsAssignableFrom(type.RuntimeType)) { typeSet.Add(type); } } } }
private static void ApplyConfiguration( ITypeCompletionContext context, ObjectFieldDefinition definition, Type?entityType, GetPagingProvider?resolvePagingProvider, PagingOptions options, FieldMiddleware placeholder) { options = context.GetSettings(options); entityType ??= context.GetType <IOutputType>(definition.Type).ToRuntimeType(); resolvePagingProvider ??= ResolvePagingProvider; IExtendedType sourceType = GetSourceType(context.TypeInspector, definition, entityType); IPagingProvider pagingProvider = resolvePagingProvider(context.Services, sourceType); IPagingHandler pagingHandler = pagingProvider.CreateHandler(sourceType, options); FieldMiddleware middleware = CreateMiddleware(pagingHandler); var index = definition.MiddlewareComponents.IndexOf(placeholder); definition.MiddlewareComponents[index] = middleware; }
private void ValidateArguments(ITypeCompletionContext context, Directive directive) { Dictionary <string, ArgumentNode> arguments = directive.ToNode().Arguments.ToDictionary(t => t.Name.Value); foreach (ArgumentNode argument in arguments.Values) { if (directive.Type.Arguments.TryGetField( argument.Name.Value, out Argument arg)) { if (!arg.Type.IsInstanceOfType(argument.Value)) { context.ReportError( DirectiveCollection_ArgumentValueTypeIsWrong( directive.Type, context.Type, directive.ToNode(), _source, arg.Name)); } } else { context.ReportError( DirectiveCollection_ArgumentDoesNotExist( directive.Type, context.Type, directive.ToNode(), _source, argument.Name.Value)); } } foreach (Argument argument in directive.Type.Arguments .Where(a => a.Type.IsNonNullType())) { if (!arguments.TryGetValue(argument.Name, out ArgumentNode arg) || arg.Value is NullValueNode) { context.ReportError( DirectiveCollection_ArgumentNonNullViolation( directive.Type, context.Type, directive.ToNode(), _source, argument.Name)); } } }
public override void OnBeforeCompleteType( ITypeCompletionContext completionContext, DefinitionBase?definition, IDictionary <string, object?> contextData) { if ((completionContext.IsQueryType ?? false) && definition is ObjectTypeDefinition objectTypeDefinition) { ITypeInspector typeInspector = completionContext.TypeInspector; IIdSerializer serializer = completionContext.Services.GetService <IIdSerializer>() ?? new IdSerializer(); ObjectFieldDefinition typeNameField = objectTypeDefinition.Fields.First( t => t.Name.Equals(IntrospectionFields.TypeName) && t.IsIntrospectionField); var index = objectTypeDefinition.Fields.IndexOf(typeNameField); CreateNodeField(typeInspector, serializer, objectTypeDefinition.Fields, index + 1); CreateNodesField(serializer, objectTypeDefinition.Fields, index + 2); } }
private static void HandleObjectType( ITypeCompletionContext completionContext, ObjectTypeDefinition definition, ISpatialConvention convention) { foreach (var field in definition.Fields) { foreach (var arg in field.Arguments) { if (arg.Type is not null && completionContext.IsNamedType <IGeoJsonInputType>(arg.Type)) { arg.Formatters.Add( new GeometryTransformerInputFormatter( convention.TransformerFactory, convention.DefaultSrid)); } } if (field.Type is not null && completionContext.IsNamedType <IGeoJsonObjectType>(field.Type)) { var argument = ArgumentDescriptor.New( completionContext.DescriptorContext, CrsFieldName); argument .Type <IntType>() .Description(Transformation_Argument_Crs_Description); field.Arguments.Add(argument.CreateDefinition()); field.MiddlewareDefinitions.Insert(0, new(FieldClassMiddlewareFactory.Create <GeometryTransformationMiddleware>( (typeof(IGeometryTransformerFactory), convention.TransformerFactory), (typeof(int), convention.DefaultSrid)))); } } }
public override void OnBeforeCompleteName(ITypeCompletionContext context, DefinitionBase?definitionBase, IDictionary <string, object?> contextData) { if (definitionBase is ObjectTypeDefinition objectTypeDefinition) { if (objectTypeDefinition.RuntimeType.IsSubclassOf(typeof(BaseEntity))) { PropertyInfo idProperty = objectTypeDefinition.RuntimeType.GetProperty(nameof(BaseEntity.Id)) !; ObjectFieldDefinition fieldDefinition = objectTypeDefinition.Fields.First(e => e.Name == context.DescriptorContext.Naming.GetMemberName(idProperty, MemberKind.ObjectField)); ObjectFieldDescriptor fieldDescriptor = ObjectFieldDescriptor.From(context.DescriptorContext, fieldDefinition); fieldDescriptor .IsProjected(true); int index = objectTypeDefinition.Fields.IndexOf(fieldDefinition); objectTypeDefinition.Fields.RemoveAt(index); objectTypeDefinition.Fields.Insert(index, fieldDescriptor.CreateDefinition()); } return; } }
public static void Complete( ITypeCompletionContext context, IComplexOutputTypeDefinition definition, Type clrType, ICollection <InterfaceType> interfaces, ITypeSystemObject interfaceOrObject, ISyntaxNode?node) { if (clrType != typeof(object)) { TryInferInterfaceUsageFromClrType(context, clrType, interfaces); } if (definition.KnownClrTypes.Count > 0) { definition.KnownClrTypes.Remove(typeof(object)); foreach (Type type in definition.KnownClrTypes.Distinct()) { TryInferInterfaceUsageFromClrType(context, type, interfaces); } } foreach (ITypeReference interfaceRef in definition.Interfaces) { if (!context.TryGetType(interfaceRef, out InterfaceType type)) { context.ReportError( CompleteInterfacesHelper_UnableToResolveInterface( interfaceOrObject, node)); } if (!interfaces.Contains(type)) { interfaces.Add(type); } } }
public void OnBeforeCompleteType(ITypeCompletionContext context, DefinitionBase definition, IDictionary <string, object> contextData) { var def = (ObjectTypeDefinition)definition; var autoList = ((List <ObjectFieldDefinition>)context.ContextData[AutoSubscriptionContext]); foreach (var mutationDef in autoList) { string subscriptionName = $"on{mutationDef.Name.Value.ToPascalCase()}"; ITypeReference mutationType = mutationDef.Type; IOutputType type = context.GetType <IOutputType>(mutationType); var descriptor = ObjectFieldDescriptor.New(context.DescriptorContext, subscriptionName); descriptor .Type(type) .Description($"Subscription for the {mutationDef.Name.Value} mutation.") .SubscribeToTopic <object>(subscriptionName) .Resolve(ctx => { return(ctx.GetEventMessage <object>()); }); def.Fields.Add(descriptor.CreateDefinition()); } def.Description += @" Snowflake provides two types of definition in its framework queries: * `onVerbObject` * `onObjectVerb(Uuid!)` `onVerbObject` subscriptions are global, and are broadcast whenever the corresponding mutation occurs. These can be used to subscribe to mutations that are triggered by the client. `onObjectVerb(Uuid!)` subscriptions are primarily used by scraping, installation, and orchestration mutations. These are used to subscribe to events happening on a specific long-existing object that may or may not be the result of a client request. There is some subtlely in the different types of subscriptions that one should be aware about. For example, `onStopEmulation` is broadcast when the `stopEmulation` mutation responds to some client. However, `onEmulationStop` is broadcast when the emulation process exits. Hence, `onStopEmulation` may never be broadcast, even if `onEmulationStop` was. In most cases, it is more useful to subscribe to the `onObjectVerb` subscription for an object whenever feasible. "; }
public static InterfaceType[] CompleteInterfaces <TInterfaceOrObject>( ITypeCompletionContext context, IReadOnlyList <ITypeReference> interfaceReferences, TInterfaceOrObject interfaceOrObject) where TInterfaceOrObject : ITypeSystemObject, IHasSyntaxNode { if (interfaceReferences.Count == 0) { return(Array.Empty <InterfaceType>()); } var implements = new InterfaceType[interfaceReferences.Count]; var index = 0; foreach (ITypeReference interfaceRef in interfaceReferences) { if (!context.TryGetType(interfaceRef, out InterfaceType? type)) { context.ReportError( CompleteInterfacesHelper_UnableToResolveInterface( interfaceOrObject, interfaceOrObject.SyntaxNode)); } if (index == 0 || Array.IndexOf(implements, type, 0, index) == -1) { implements[index++] = type !; } } if (index < implements.Length) { Array.Resize(ref implements, index); } return(implements); }
private void CompleteTypeSet( ITypeCompletionContext context, UnionTypeDefinition definition) { var typeSet = new HashSet <ObjectType>(); OnCompleteTypeSet(context, definition, typeSet); foreach (ObjectType objectType in typeSet) { _typeMap[objectType.Name] = objectType; } if (typeSet.Count == 0) { context.ReportError(SchemaErrorBuilder.New() .SetMessage(TypeResources.UnionType_MustHaveTypes) .SetCode(ErrorCodes.Schema.MissingType) .SetTypeSystemObject(this) .AddSyntaxNode(SyntaxNode) .Build()); } }
protected virtual void OnCompleteTypeSet( ITypeCompletionContext context, UnionTypeDefinition definition, ISet <ObjectType> typeSet) { foreach (ITypeReference typeReference in definition.Types) { if (context.TryGetType(typeReference, out ObjectType ot)) { typeSet.Add(ot); } else { context.ReportError(SchemaErrorBuilder.New() .SetMessage(TypeResources.UnionType_UnableToResolveType) .SetCode(ErrorCodes.Schema.MissingType) .SetTypeSystemObject(this) .SetExtension(_typeReference, typeReference) .AddSyntaxNode(SyntaxNode) .Build()); } } }