Exemplo n.º 1
0
        public void SupportsMutationObject()
        {
            var schemaProvider = SchemaBuilder.FromObject <TestSchema>(false);

            schemaProvider.AddMutationFrom(new PeopleMutations());
            // Add a argument field with a require parameter
            var gql = new QueryRequest {
                Query = @"mutation AddPerson($names: [String]) {
  addPersonInput(nameInput: $names) {
    id name lastName
  }
}",
                // object will come through as json in the request
                Variables = new QueryVariables {
                    { "names", Newtonsoft.Json.JsonConvert.DeserializeObject("{\"name\": \"Lisa\", \"lastName\": \"Simpson\"}") }
                }
            };
            dynamic addPersonResult = new TestSchema().QueryObject(gql, schemaProvider);

            Assert.Empty(addPersonResult.Errors);
            addPersonResult = Enumerable.First(addPersonResult.Data);
            addPersonResult = addPersonResult.Value;
            // we only have the fields requested
            Assert.Equal(3, addPersonResult.GetType().GetFields().Length);
            Assert.Equal("id", addPersonResult.GetType().GetFields()[0].Name);
            Assert.Equal(0, addPersonResult.id);
            Assert.Equal("name", addPersonResult.GetType().GetFields()[1].Name);
            Assert.Equal("Lisa", addPersonResult.name);
            Assert.Equal("Simpson", addPersonResult.lastName);
        }
Exemplo n.º 2
0
        public void SupportsMutationOptional()
        {
            var schemaProvider = SchemaBuilder.FromObject <TestSchema>(false);

            schemaProvider.AddMutationFrom(new PeopleMutations());
            // Add a argument field with a require parameter
            var gql = new QueryRequest {
                Query     = @"
                mutation AddPerson($name: String) {
  addPerson(name: $name) {
    id name
  }
}",
                Variables = new QueryVariables {
                }
            };
            dynamic addPersonResult = new TestSchema().QueryObject(gql, schemaProvider).Data["addPerson"];

            // we only have the fields requested
            Assert.Equal(2, addPersonResult.GetType().GetFields().Length);
            Assert.Equal("id", addPersonResult.GetType().GetFields()[0].Name);
            Assert.Equal(555, addPersonResult.id);
            Assert.Equal("name", addPersonResult.GetType().GetFields()[1].Name);
            Assert.Equal("Default", addPersonResult.name);
        }