Пример #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);
        }
Пример #2
0
        public void EnsureLookup()
        {
            if (_lookup == null)
            {
                _lookup = new GraphTypesLookup();

                var ctx = new TypeCollectionContext(ResolveType, (name, graphType) =>
                {
                    _lookup[name] = graphType;
                });

                _lookup.AddType(Query, ctx);
                _lookup.AddType(Mutation, ctx);
            }
        }
Пример #3
0
        public void EnsureLookup()
        {
            if (_lookup == null)
            {
                _lookup = new GraphTypesLookup();

                var ctx = new TypeCollectionContext(ResolveType, (name, graphType) =>
                {
                    _lookup[name] = graphType;
                });

                _lookup.AddType(Query, ctx);
                _lookup.AddType(Mutation, ctx);
            }
        }
Пример #4
0
        private GraphTypesLookup CreateTypesLookup()
        {
            var resolvedTypes = _additionalTypes.Select(ResolveType).ToList();

            var types = new List <GraphType>
            {
                Query,
                Mutation
            }
            .Concat(resolvedTypes)
            .Where(x => x != null)
            .ToList();

            return(GraphTypesLookup.Create(types, ResolveType));
        }
        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);
        }
Пример #6
0
        private GraphTypesLookup CreateTypesLookup()
        {
            var resolvedTypes = _additionalTypes.Select(t => ResolveType(t.GetNamedType())).ToList();

            var types = _additionalInstances.Concat(
                new IGraphType[]
            {
                Query,
                Mutation,
                Subscription
            })
                        .Concat(resolvedTypes)
                        .Where(x => x != null)
                        .ToList();

            return(GraphTypesLookup.Create(types, _directives, ResolveType));
        }
Пример #7
0
        public static GraphTypesLookup Create(IEnumerable <GraphType> types, Func <Type, GraphType> 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);
            });

            return(lookup);
        }
Пример #8
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);
        }
Пример #9
0
 private GraphTypesLookup CreateTypesLookup()
 {
     return(GraphTypesLookup.Create(new[] { Query, Mutation }, ResolveType));
 }