private static void CompileMiddleware(
            ITypeCompletionContext context,
            ObjectFieldDefinition definition,
            ITypeReference argumentTypeReference,
            FieldMiddleware placeholder,
            string?scope)
        {
            IType resolvedType = context.GetType <IType>(argumentTypeReference);

            if (!(resolvedType.ElementType().NamedType() is ISortInputType type))
            {
                throw Sorting_TypeOfInvalidFormat(resolvedType);
            }

            ISortConvention convention = context.DescriptorContext.GetSortConvention(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;
        }
Exemplo n.º 2
0
        protected override void OnCompleteType(
            ITypeCompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            EntityType = context.GetType <IOutputType>(
                TypeReference.Create <T>());
        }
Exemplo n.º 3
0
        protected override void OnCompleteType(
            ITypeCompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            ItemType = context.GetType <IOutputType>(
                context.TypeInspector.GetTypeRef(typeof(T)));
        }
Exemplo n.º 4
0
        protected override void OnCompleteType(
            ITypeCompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            EdgeType = context.GetType <EdgeType <T> >(
                context.TypeInspector.GetTypeRef(typeof(EdgeType <T>)));
        }
Exemplo n.º 5
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);

            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;
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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;
        }
        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.
";
        }