예제 #1
0
        public async Task TestPost()
        {
            var query = new Query <Pokemon>("pokemon")
                        .AddArguments(new { name = "pikachu" })
                        .AddField(p => p.Name);

            using var client = new GraphQLClient(URL);

            Pokemon pikachu = await client.Post <Pokemon>(query);

            Assert.NotNull(pikachu);
            Assert.Equal("Pikachu", pikachu.Name);
        }
예제 #2
0
        public async Task TestError()
        {
            var query = new Query <Pokemon>("wrongQueryName")
                        .AddArguments(new { name = "pikachu" })
                        .AddField(p => p.Name);

            using var client = new GraphQLClient(URL);

            GraphQLClientException exception = await Assert.ThrowsAsync <GraphQLClientException>(async() => await client.Post <Pokemon>(query));

            Assert.Equal(
                $"The GraphQL request returns errors.{Environment.NewLine}Cannot query field \"wrongQueryName\" on type \"Query\".",
                exception.Message);
        }