Example #1
0
        public Expression <Func <IgnoreTestSchema, Album> > AddAlbum(IgnoreTestSchema db, Album args)
        {
            var newAlbum = new Album
            {
                Id   = new Random().Next(100),
                Name = args.Name,
            };

            db.Albums.Add(newAlbum);
            return(ctx => ctx.Albums.First(a => a.Id == newAlbum.Id));
        }
Example #2
0
        public Expression <Func <IgnoreTestSchema, IEnumerable <Album> > > AddAlbum2(IgnoreTestSchema db, Album args)
        {
            var newAlbum = new Album
            {
                Id   = new Random().Next(100),
                Name = args.Name,
            };

            db.Albums.Add(newAlbum);
            return(ctx => ctx.Albums);
        }
Example #3
0
        public void TestIgnoreQueryPasses()
        {
            var schemaProvider = SchemaBuilder.FromObject <IgnoreTestSchema>(false);
            // Add a argument field with a require parameter
            var gql = new QueryRequest {
                Query = @"query Test { albums { id } }",
            };
            var results = new IgnoreTestSchema().QueryObject(gql, schemaProvider);

            Assert.Empty(((IEnumerable)results.Data["albums"]));
        }
Example #4
0
        public void TestIgnoreQueryFails()
        {
            var schemaProvider = SchemaBuilder.FromObject <IgnoreTestSchema>(false);
            // Add a argument field with a require parameter
            var gql = new QueryRequest {
                Query = @"query Test { movies { id } }",
            };
            dynamic results = new IgnoreTestSchema().QueryObject(gql, schemaProvider).Errors;
            var     err     = Enumerable.First(results);

            Assert.Equal("Error compiling query 'movies'. Field 'movies' not found on current context 'IgnoreTestSchema'", err.Message);
        }
Example #5
0
        public void TestIgnoreAllInQuery()
        {
            var schemaProvider = SchemaBuilder.FromObject <IgnoreTestSchema>(false);
            // Add a argument field with a require parameter
            var gql = new QueryRequest {
                Query     = @"query Test {
  albums {
    id hiddenInputField hiddenField
  }
}",
                Variables = new QueryVariables {
                }
            };
            var results = new IgnoreTestSchema().QueryObject(gql, schemaProvider);
            var error   = results.Errors.First();

            Assert.Equal("Error compiling query 'albums'. Field 'hiddenField' not found on current context 'Album'", error.Message);
        }
Example #6
0
        public void TestIgnoreAllInInput()
        {
            var schemaProvider = SchemaBuilder.FromObject <IgnoreTestSchema>(false);

            schemaProvider.AddMutationFrom(new IgnoreTestMutations());
            // Add a argument field with a require parameter
            var gql = new QueryRequest {
                Query     = @"mutation Test($name: String, $hiddenField: String) {
  addAlbum(name: $name, hiddenField: $hiddenField) {
    id
  }
}",
                Variables = new QueryVariables {
                    { "name", "Balance, Not Symmetry" },
                    { "hiddenField", "yeh" },
                }
            };
            var results = new IgnoreTestSchema().QueryObject(gql, schemaProvider);
            var error   = results.Errors.First();

            Assert.Equal("Error compiling query 'addAlbum(name: $name, hiddenField: $hiddenField)'. No argument 'hiddenField' found on field 'addAlbum'", error.Message);
        }
Example #7
0
        public void TestIgnoreInputPasses()
        {
            var schemaProvider = SchemaBuilder.FromObject <IgnoreTestSchema>(false);

            schemaProvider.AddMutationFrom(new IgnoreTestMutations());
            // Add a argument field with a require parameter
            var gql = new QueryRequest {
                Query     = @"mutation Test($name: String) {
  addAlbum(name: $name) {
    id name hiddenInputField
  }
}",
                Variables = new QueryVariables {
                    { "name", "Balance, Not Symmetry" },
                }
            };
            var     results = new IgnoreTestSchema().QueryObject(gql, schemaProvider);
            dynamic data    = results.Data["addAlbum"];

            Assert.Equal("Balance, Not Symmetry", data.name);
            Assert.Null(data.hiddenInputField); // not hidden from query
            Assert.InRange(data.id, 0, 100);
        }