Ejemplo n.º 1
0
        public void BasicExample_Works()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(GenericsSchema));

            var query = @"
                {
                    echoGenerics{data}
                }
            ";

            var expected = @"{
              echoGenerics: {
                data: """"
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 2
0
        public void WithComplexParameters_Works()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoSchema));

            var query = @"{
                  testRequest(request:{
                    complexRequests:[{
                            innerData:""345""
                        }]
                    }) {value}
                }";

            var expected = @"{
              testRequest: {value:5}
                }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 3
0
        public void GetOffset_IsSafe()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(DateSchema));

            var query = @"
                {dates(dates:{offset:""5/1/2012""}) {
                  offset
                }}
            ";

            var expected = @"{
              dates: {
                offset:""2012-05-01T06:00:00Z""
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 4
0
        public void GetTimeSpan_IsSafe()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(DateSchema));

            var query = @"
                {dates(dates:{timeSpan:""1.23:59:59""}) {
                    timeSpan
                }}
            ";

            var expected = @"{
              dates: {
                timeSpan:""1.23:59:59""
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 5
0
        public void QueryProject_Works()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(UserSchema));

            var query = @"{
                getUser {
                   firstName
                }
            }";

            var expected = @"{
                getUser:{
                                firstName: ""Hakob""
                        }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 6
0
        public async void OperationLimit_WhenNotExceededWithMutations_Runs()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoStateSchema));

            var query = @"
                mutation SetState{
                    setState (request:Open){
                        state
                    }
                }
                query GetState{
                    getState{
                        state
                    }
                }
            ";

            await DocumentOperations.ExecuteOperationsAsync(schema, null, query, maxOperationNodes : 2);
        }
        public void WithComplexParameters_HaveCorrectType()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(AsyncSchema));

            var query = @"{
                  __type(name : ""Input_InnerRequest"") {
                    name
                    kind
                }}";

            var expected = @"{
              __type: {
                name: ""Input_InnerRequest"",
                kind: ""INPUT_OBJECT""
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 8
0
        public async void OperationLimit_WhenExceededWithMutations_Throws()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoStateSchema));

            var query = @"
                mutation SetState{
                    setState (request:Open){
                        state
                    }
                }
                query GetState{
                    getState{
                        state
                    }
                }
            ";

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(() =>
                                                                          DocumentOperations.ExecuteOperationsAsync(schema, null, query, maxOperationNodes: 1));
        }
Ejemplo n.º 9
0
        public void BasicExample_WithDecimal_Works()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoStateSchema));

            var query = @"
                mutation SetState{
                    set(request:{decimal:24.15, data:2}){
                        decimal
                    }
                }
            ";

            var expected = @"{
              set: {
                decimal: 24.15
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 10
0
        public void BasicExample_WithEnums_Works()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoStateSchema));

            var query = @"
                mutation SetState{
                    setState (request:Open){
                        state
                    }
                }
            ";

            var expected = @"{
              setState: {
                state: ""Open""
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 11
0
        public void GetUtcDates_IsSafe()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(DateSchema));

            var query = @"
                {dates(dates:{offset:""2013-07-02T09:00:00Z"", dateTime:""2013-07-02T09:00Z""}) {
                  y2k
                  y2kUtc
                }}
            ";

            var expected = @"{
              dates: {
                y2k:""2000-01-01T00:00:00"",
                y2kUtc:""2000-01-01T00:00:00Z""
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 12
0
        public void BasicExample_Works()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoStateSchema));

            var query = @"
                mutation SetData{
                    setData (request:4){
                        data
                    }
                }
            ";

            var expected = @"{
              setData: {
                data: 4
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 13
0
        public void BasicExample_Works()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(StarWarsAttributeSchema));

            var query = @"
                query HeroNameQuery {
                  hero {
                    name
                  }
                }
            ";

            var expected = @"{
              hero: {
                name: 'R2-D2'
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 14
0
        public async Task LargeLists_Perform_UnderThreshold()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());

            var schema = schemaGenerator.CreateSchema(typeof(PerformanceSchema));

            var query = @"{
                  testList{
                    date
                    enum
                    value
                    nullValue
                    decimalValue
                    timeSpan
                    byteArray
                    stringValue
                    values{
                        value{
                            complicatedResponse{
                            echo
                            data
                            }
                        }
                    }
                 }
            }";

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var result = await DocumentOperations.ExecuteOperationsAsync(schema, null, query, validate : false);

            stopwatch.Stop();

            _output.WriteLine($"Total Milliseconds: {stopwatch.ElapsedMilliseconds}");

            Assert.True(stopwatch.Elapsed.TotalSeconds < 2);
            Assert.Null(result.Errors);
        }
Ejemplo n.º 15
0
        public void SetAdvancedString_WithStringParam_Works(string var1, string var2)
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoStateSchema));

            var query = @"
                mutation SetState($str:" + var1 + @", $str2:" + var2 + @"){
                    set:setAdvancedString(request:{requiredString:$str, notRequiredString:$str2}){
                        requiredString
                        notRequiredString
                    }
                }
            ";

            var expected = @"{
              set: {
                requiredString:""Yes"",
                notRequiredString: """"
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected, "{str:\"Yes\", str2:\"\"}");
        }
Ejemplo n.º 16
0
        public void SetAdvanced_WithSameQuery_WorksBackwardsCompatible()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoStateSchema));

            var query = @"
                mutation SetState{
                    set:setAdvanced(request:{decimal:24.15, data:2}){
                        data
                        state
                    }
                }
            ";

            var expected = @"{
              set: {
                data: 2,
                state: ""Open""
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 17
0
        public void GetTimeZoneOffset_IsSafe()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(DateSchema));

            var query = @"
                {dates(dates:{offset:""2013-07-02T09:00:00-06:00"", dateTime:""2013-07-02T09:00-06:00""}) {
                  offset
                  dateTime
                  dateUTC
                }}
            ";

            var expected = @"{
              dates: {
                offset:""2013-07-02T09:00:00-06:00"",
                dateTime:""2013-07-02T09:00:00-06:00"",
                dateUTC:""2013-07-02T15:00:00Z""
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected);
        }
Ejemplo n.º 18
0
        public async void OperationLimit_WhenNotExceededWithParameters_Runs()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoStateSchema));

            var query = @"
                mutation SetState($begin: Date!,  $end: Date!, $test: String, $test2: String){
                    setState (request:Open){
                        state
                    }
                }
                query GetState($begin: Date!,  $end: Date!, $test: String, $test2: String){
                    getState{
                        state
                    }
                    state2:getState{
                        state
                    }
                }
            ";

            await DocumentOperations.ExecuteOperationsAsync(schema, null, query, maxOperationNodes : 3);
        }
Ejemplo n.º 19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var deserializer = new YamlDeserializer();
            var settings     = deserializer.DeserializeConfiguration <Settings>();

            settings.DynamicObjects.AddDefaultFields();

            var objectGenerator = new ObjectGenerator();

            objectGenerator.CreateObjects(settings.DynamicObjects);

            services.AddAllServices(settings);

            var entityTypes = CustomTypeBuilder.GetAllCustomTypes();
            var schemaTypes = new List <Type>();

            foreach (var type in entityTypes)
            {
                IServiceProvider serviceProvider = services.BuildServiceProvider();
                var service    = serviceProvider.GetRequiredService <DynamicObjectService>();
                var schemaType = Activator.CreateInstance(typeof(DynamicObjectType <>).MakeGenericType(type), new object[] { service }).GetType();
                schemaTypes.Add(schemaType);
                services.AddSingleton(schemaType);
            }

            IServiceProvider schemaServiceProvider = services.BuildServiceProvider();
            var schemaGenerator = new SchemaGenerator(schemaServiceProvider);
            var schema          = schemaGenerator.CreateSchema(schemaTypes.ToArray());

            SchemaPrinter printer = new SchemaPrinter(schema);
            string        wat     = printer.Print();

            services.AddSingleton <IDocumentExecuter, DocumentExecuter>();
            services.AddSingleton <ISchema>(schema);
        }
Ejemplo n.º 20
0
        public void GetNullDecimalAsVariable_IsSafe()
        {
            var schemaGenerator = new SchemaGenerator(new MockServiceProvider());
            var schema          = schemaGenerator.CreateSchema(typeof(EchoSchema));

            var query = @"
                query($ts:Decimal!)
                {
                    testRequest(request:{decimal:$ts}){decimalValue}
                }                
            ";

            var variables = @"{
                ts:1.23
            }";

            var expected = @"{
              testRequest: {
                decimalValue:1.23
              }
            }";

            GraphAssert.QuerySuccess(schema, query, expected, variables);
        }