Ejemplo n.º 1
0
        public static void RegisterDependencies(
            this ITypeDiscoveryContext context,
            ObjectTypeDefinition definition)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (definition is null)
            {
                throw new ArgumentNullException(nameof(definition));
            }

            context.RegisterDependencyRange(
                definition.GetInterfaces(),
                TypeDependencyKind.Completed);

            RegisterAdditionalDependencies(context, definition);
            RegisterDirectiveDependencies(context, definition);
            RegisterFieldDependencies(context, definition.Fields);

            foreach (ObjectFieldDefinition field in definition.Fields)
            {
                if (field.Resolver is null)
                {
                    if (field.Expression is not null)
                    {
                        context.RegisterResolver(
                            field.Name,
                            field.Expression,
                            definition.RuntimeType,
                            field.ResolverType);
                    }
                    else if (field.ResolverMember is not null)
                    {
                        context.RegisterResolver(
                            field.Name,
                            field.ResolverMember,
                            definition.RuntimeType,
                            field.ResolverType);
                    }
                    else if (field.Member is not null)
                    {
                        context.RegisterResolver(
                            field.Name,
                            field.Member,
                            definition.RuntimeType,
                            field.ResolverType);
                    }
                }
            }
        }