protected override void OnCompleteType(
            ICompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            EdgeType = context.GetType <EdgeType <T> >(
                ClrTypeReference.FromSchemaType <EdgeType <T> >());
        }
Beispiel #2
0
        protected override void OnCompleteType(
            ICompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteType(context, definition);

            EdgeType = context.GetType <EdgeType <T> >(
                new ClrTypeReference(typeof(EdgeType <T>),
                                     TypeContext.Output));
        }
Beispiel #3
0
        protected override void OnCompleteName(
            ICompletionContext context,
            ObjectTypeDefinition definition)
        {
            base.OnCompleteName(context, definition);

            INamedType namedType = context.GetType <INamedType>(
                new ClrTypeReference(typeof(T), TypeContext.Output));

            Name = namedType.Name + "Edge";
        }
Beispiel #4
0
        private static void CompileMiddleware(
            ICompletionContext context,
            ObjectFieldDefinition definition,
            ITypeReference argumentTypeReference,
            FieldMiddleware placeholder)
        {
            IFilterInputType type =
                context.GetType <IFilterInputType>(argumentTypeReference);
            Type middlewareType = _middlewareDefinition
                                  .MakeGenericType(type.EntityType);
            FieldMiddleware middleware =
                FieldClassMiddlewareFactory.Create(middlewareType);
            int index = definition.MiddlewareComponents.IndexOf(placeholder);

            definition.MiddlewareComponents[index] = middleware;
        }
Beispiel #5
0
        protected virtual void OnCompleteField(
            ICompletionContext context,
            TDefinition definition)
        {
            DeclaringType = context.Type;
            Type          = context.GetType <TType>(_definition.Type);
            ClrType       = Type is IHasClrType hasClrType
                ? hasClrType.ClrType
                : typeof(object);

            var directives = new DirectiveCollection(
                this, _definition.Directives);

            directives.CompleteCollection(context);
            Directives = directives;
        }
Beispiel #6
0
        internal void CompleteField(ICompletionContext context)
        {
            DeclaringType = context.Type;
            Type          = context.GetType <TType>(_definition.Type);
            ClrType       = Type.NamedType() is IHasClrType hasClrType
                ? hasClrType.ClrType
                : typeof(object);

            var directives = new DirectiveCollection(
                this, _definition.Directives);

            directives.CompleteCollection(context);
            Directives = directives;

            OnCompleteField(context, _definition);
            _definition = null;
        }
Beispiel #7
0
        private static void CompileMiddleware(
            ICompletionContext context,
            ObjectFieldDefinition definition,
            ITypeReference argumentTypeReference,
            FieldMiddleware placeholder)
        {
            ISortingNamingConvention convention =
                context.DescriptorContext.GetSortingNamingConvention();

            ISortInputType type           = context.GetType <ISortInputType>(argumentTypeReference);
            Type           middlewareType = _middlewareDefinition.MakeGenericType(type.EntityType);

            FieldMiddleware middleware =
                FieldClassMiddlewareFactory.Create(
                    middlewareType,
                    SortMiddlewareContext.Create(convention.ArgumentName));

            int index = definition.MiddlewareComponents.IndexOf(placeholder);

            definition.MiddlewareComponents[index] = middleware;
        }
        public void OnBeforeCompleteType(ICompletionContext 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.")
                .Resolver(ctx =>
                {
                    return(ctx.GetEventMessage().Payload);
                });
                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.
";
        }