Ejemplo n.º 1
0
        public static GraphTypesLookup Create(
            IEnumerable <IGraphType> types,
            IEnumerable <DirectiveGraphType> directives,
            Func <Type, IGraphType> resolveType,
            IFieldNameConverter fieldNameConverter,
            bool seal = false)
        {
            var lookup = new GraphTypesLookup
            {
                FieldNameConverter = fieldNameConverter ?? CamelCaseFieldNameConverter.Instance
            };

            var ctx = new TypeCollectionContext(resolveType, (name, graphType, context) =>
            {
                if (lookup[name] == null)
                {
                    lookup.AddType(graphType, context);
                }
            });

            foreach (var type in types)
            {
                lookup.AddType(type, ctx);
            }

            var introspectionType = typeof(SchemaIntrospection);

            lookup.HandleField(introspectionType, SchemaIntrospection.SchemaMeta, ctx);
            lookup.HandleField(introspectionType, SchemaIntrospection.TypeMeta, ctx);
            lookup.HandleField(introspectionType, SchemaIntrospection.TypeNameMeta, ctx);

            foreach (var directive in directives)
            {
                if (directive.Arguments == null)
                {
                    continue;
                }

                foreach (var arg in directive.Arguments)
                {
                    if (arg.ResolvedType != null)
                    {
                        arg.ResolvedType = lookup.ConvertTypeReference(directive, arg.ResolvedType);
                    }
                    else
                    {
                        arg.ResolvedType = lookup.BuildNamedType(arg.Type, ctx.ResolveType);
                    }
                }
            }

            lookup.ApplyTypeReferences();

            Debug.Assert(ctx.InFlightRegisteredTypes.Count == 0);
            lookup._sealed = seal;

            return(lookup);
        }
        public static GraphTypesLookup Create(
            IEnumerable <IGraphType> types,
            IEnumerable <DirectiveGraphType> directives,
            Func <Type, IGraphType> resolveType,
            IFieldNameConverter fieldNameConverter)
        {
            var lookup = new GraphTypesLookup();

            lookup.FieldNameConverter = fieldNameConverter ?? new CamelCaseFieldNameConverter();

            var ctx = new TypeCollectionContext(resolveType, (name, graphType, context) =>
            {
                if (lookup[name] == null)
                {
                    lookup.AddType(graphType, context);
                }
            });

            types.Apply(type =>
            {
                lookup.AddType(type, ctx);
            });

            var introspectionType = typeof(SchemaIntrospection);

            lookup.HandleField(introspectionType, SchemaIntrospection.SchemaMeta, ctx);
            lookup.HandleField(introspectionType, SchemaIntrospection.TypeMeta, ctx);
            lookup.HandleField(introspectionType, SchemaIntrospection.TypeNameMeta, ctx);

            directives.Apply(directive =>
            {
                directive.Arguments?.Apply(arg =>
                {
                    if (arg.ResolvedType != null)
                    {
                        arg.ResolvedType = lookup.ConvertTypeReference(directive, arg.ResolvedType);
                        return;
                    }

                    arg.ResolvedType = lookup.BuildNamedType(arg.Type, ctx.ResolveType);
                });
            });

            lookup.ApplyTypeReferences();

            return(lookup);
        }
Ejemplo n.º 3
0
        public static GraphTypesLookup Create(
            IEnumerable <IGraphType> types,
            IEnumerable <DirectiveGraphType> directives,
            Func <Type, IGraphType> resolveType)
        {
            var lookup = new GraphTypesLookup();

            var ctx = new TypeCollectionContext(resolveType, (name, graphType, context) =>
            {
                if (lookup[name] == null)
                {
                    lookup.AddType(graphType, context);
                }
            });

            types.Apply(type =>
            {
                lookup.AddType(type, ctx);
            });

            lookup.HandleField(SchemaIntrospection.SchemaMeta, ctx);
            lookup.HandleField(SchemaIntrospection.TypeMeta, ctx);
            lookup.HandleField(SchemaIntrospection.TypeNameMeta, ctx);

            directives.Apply(directive =>
            {
                directive.Arguments?.Apply(arg =>
                {
                    if (arg.ResolvedType != null)
                    {
                        return;
                    }

                    arg.ResolvedType = lookup.BuildNamedType(arg.Type, ctx.ResolveType);
                });
            });

            return(lookup);
        }