public void Read_SubscriptionType()
        {
            /* Given */
            var subscription = new __Type
            {
                Kind = __TypeKind.OBJECT,
                Name = "S"
            };

            var schema = new __Schema
            {
                SubscriptionType = subscription,
                Types            = new List <__Type>
                {
                    subscription
                }
            };

            var builder = new SchemaBuilder();
            var reader  = new IntrospectionSchemaReader(
                builder,
                new IntrospectionResult
            {
                Schema = schema
            });

            /* When */
            reader.Read();

            /* Then */
            builder.TryGetType <ObjectType>("Subscription", out var subscriptionType);
            Assert.NotNull(subscriptionType);
        }
Ejemplo n.º 2
0
        public __Schema Build(GraphQLApiModel model)
        {
            _model         = model;
            _stringNotNull = _model.GetScalarTypeDef("String").TypeRefNotNull;
            _schema        = _model.Schema_ = new __Schema();

            // Create type objects without internal details; for typeDef and its typeRefs
            foreach (var typeDef in _model.Types)
            {
                if (!typeDef.IsSchemaType())
                {
                    continue;
                }
                CreateTypeObject(typeDef);
                foreach (var typeRef in typeDef.TypeRefs)
                {
                    SetupTypeObject(typeRef);
                }
            }

            // Build types internals - fields, etc
            BuildTypeObjectsInternals();
            BuildDirectives();
            CompleteSchemaObject();
            return(_schema);
        }
        public void Read_QueryType()
        {
            /* Given */
            var query = new __Type
            {
                Kind = __TypeKind.OBJECT,
                Name = "Q"
            };

            var schema = new __Schema
            {
                QueryType = query,
                Types     = new List <__Type>
                {
                    query
                }
            };

            var builder = new SchemaBuilder();
            var reader  = new IntrospectionSchemaReader(
                builder,
                new IntrospectionResult
            {
                Schema = schema
            });

            /* When */
            reader.Read();

            /* Then */
            builder.TryGetType <ObjectType>("Query", out var queryType);
            Assert.NotNull(queryType);
        }
        public void Read_Scalars()
        {
            /* Given */
            var types = ScalarType.Standard
                        .Select(s => s.Type)
                        .Select(scalar => new __Type
            {
                Kind = __TypeKind.SCALAR,
                Name = scalar.Name
            }).ToList();

            var schema = new __Schema
            {
                Types = types
            };

            var builder = new SchemaBuilder();
            var reader  = new IntrospectionSchemaReader(
                builder,
                new IntrospectionResult
            {
                Schema = schema
            });

            /* When */
            reader.Read();

            /* Then */
            foreach (var scalarType in ScalarType.Standard
                     .Select(s => s.Type))
            {
                Assert.True(builder.TryGetType <ScalarType>(scalarType.Name, out _));
            }
        }
Ejemplo n.º 5
0
    public static SchemaBuilder AddIntrospectedSchema(this SchemaBuilder builder, __Schema schema)
    {
        foreach (var schemaType in schema.Types)
        {
            builder.Add(schemaType);
        }

        return(builder);
    }
        public void Read_UnionType()
        {
            /* Given */
            var object1 = new __Type
            {
                Kind = __TypeKind.OBJECT,
                Name = "object1"
            };
            var object2 = new __Type
            {
                Kind = __TypeKind.OBJECT,
                Name = "object2"
            };
            var introspectedType = new __Type
            {
                Kind          = __TypeKind.UNION,
                Name          = "U",
                PossibleTypes = new List <__Type>
                {
                    object1,
                    object2
                }
            };

            var schema = new __Schema
            {
                Types = new List <__Type>
                {
                    object1,
                    introspectedType,
                    object2
                }
            };

            var builder = new SchemaBuilder();
            var reader  = new IntrospectionSchemaReader(
                builder,
                new IntrospectionResult
            {
                Schema = schema
            });

            /* When */
            reader.Read();

            /* Then */
            Assert.True(builder.TryGetType <UnionType>(introspectedType.Name, out var type));
            Assert.Single(type.PossibleTypes, possibleType => possibleType.Key == "object1");
            Assert.Single(type.PossibleTypes, possibleType => possibleType.Key == "object2");
        }
        public void Read_InputObjectType_with_field()
        {
            /* Given */
            var type = new __Type
            {
                Kind        = __TypeKind.INPUT_OBJECT,
                Name        = "object",
                InputFields = new List <__InputValue>
                {
                    new __InputValue
                    {
                        Name = "field1",
                        Type = new __Type
                        {
                            Kind = __TypeKind.SCALAR,
                            Name = "Int"
                        }
                    }
                }
            };

            var schema = new __Schema
            {
                Types = new List <__Type>
                {
                    type
                }
            };

            var builder = new SchemaBuilder();
            var reader  = new IntrospectionSchemaReader(
                builder,
                new IntrospectionResult
            {
                Schema = schema
            });

            /* When */
            reader.Read();

            /* Then */
            builder.TryGetType <InputObjectType>(type.Name, out var inputObjectType);
            Assert.NotNull(inputObjectType);
            builder.Connections(connections =>
            {
                Assert.True(connections.TryGetInputField(inputObjectType, "field1", out var field1));
                Assert.Equal(ScalarType.Int, field1.Type);
            });
        }
Ejemplo n.º 8
0
 protected __Type ExtractAppropriate__TypeForOperation(__Schema schema, GraphQLParser.OperationDefinitionContext context)
 {
     if (context.operationType().GetText().ToLower() == "mutation")
     {
         return(schema.mutationType);
     }
     else if (context.operationType().GetText().ToLower() == "query")
     {
         return(schema.queryType);
     }
     else
     {
         Error($"Unexpected operation type - expected 'query' or 'mutation' received - {context.operationType().GetText()}", context);
         return(null);
     }
 }
        public void Read_Enum_with_values()
        {
            /* Given */
            var introspectedType = new __Type
            {
                Kind       = __TypeKind.ENUM,
                Name       = "T",
                EnumValues = new List <__EnumValue>
                {
                    new __EnumValue
                    {
                        Name        = "VALUE1",
                        Description = "description"
                    }
                }
            };

            var schema = new __Schema
            {
                Types = new List <__Type>
                {
                    introspectedType
                }
            };

            var builder = new SchemaBuilder();
            var reader  = new IntrospectionSchemaReader(
                builder,
                new IntrospectionResult
            {
                Schema = schema
            });

            /* When */
            reader.Read();

            /* Then */
            Assert.True(builder.TryGetType <EnumType>(introspectedType.Name, out var type));
            Assert.Single(type.Values, value => value.Key == "VALUE1");
        }
Ejemplo n.º 10
0
 public __SchemaContainer(__Schema s)
 {
     __schema = s;
 }
        public void Read_ObjectType_with_field()
        {
            /* Given */
            var type = new __Type
            {
                Kind   = __TypeKind.OBJECT,
                Name   = "object",
                Fields = new List <__Field>
                {
                    new __Field
                    {
                        Name = "field1",
                        Type = new __Type
                        {
                            Kind = __TypeKind.SCALAR,
                            Name = "Int"
                        },
                        Args = new List <__InputValue>
                        {
                            new __InputValue
                            {
                                Name = "arg1",
                                Type = new __Type
                                {
                                    Kind = __TypeKind.SCALAR,
                                    Name = "String"
                                }
                            }
                        }
                    }
                }
            };

            var schema = new __Schema
            {
                Types = new List <__Type>
                {
                    type
                }
            };

            var builder = new SchemaBuilder();
            var reader  = new IntrospectionSchemaReader(
                builder,
                new IntrospectionResult
            {
                Schema = schema
            });

            /* When */
            reader.Read();

            /* Then */
            builder.TryGetType <ObjectType>(type.Name, out var objectType);
            Assert.NotNull(objectType);
            builder.Connections(connections =>
            {
                Assert.True(connections.TryGetField(objectType, "field1", out var field1));
                Assert.Equal(ScalarType.Int, field1.Type);
                Assert.Single(field1.Arguments, arg => arg.Key == "arg1" &&
                              ScalarType.String.Equals(arg.Value.Type));
            });
        }
Ejemplo n.º 12
0
 /// <summary>
 ///     Create reader
 /// </summary>
 /// <param name="builder">Write types to builder</param>
 /// <param name="result">Introspection result to use as source</param>
 public IntrospectionSchemaReader(SchemaBuilder builder, IntrospectionResult result)
 {
     _builder = builder;
     _schema  = result.Schema;
 }