public async Task Ensure_Benchmark_Query_GetTwoHerosWithFriendsQuery()
 {
     Snapshot.FullName();
     await ExpectValid(
         FileResource.Open("GetTwoHerosWithFriendsQuery.graphql"))
     .MatchSnapshotAsync();
 }
 public async Task TypeNameFieldIsCorrectlyExecutedOnInterfaces()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query foo {
             hero(episode: NEW_HOPE) {
                 __typename
                 id
                 name
                 ... on Human {
                     __typename
                     homePlanet
                 }
                 ... on Droid {
                     __typename
                     primaryFunction
                 }
                 friends {
                     nodes {
                         __typename
                         ... on Human {
                             __typename
                             homePlanet
                         }
                         ... on Droid {
                             __typename
                             primaryFunction
                         }
                     }
                 }
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task Ensure_Benchmark_Query_LargeQuery()
 {
     Snapshot.FullName();
     await ExpectValid(
         FileResource.Open("LargeQuery.graphql"))
     .MatchSnapshotAsync();
 }
        public static AssertSettings CreateIntegrationTest(
            Descriptors.Operations.RequestStrategy requestStrategy =
            Descriptors.Operations.RequestStrategy.Default,
            TransportProfile[]?profiles        = null,
            [CallerMemberName] string?testName = null)
        {
            SnapshotFullName snapshotFullName = Snapshot.FullName();
            string           testFile         = System.IO.Path.Combine(
                snapshotFullName.FolderPath,
                testName + "Test.cs");
            string ns = "StrawberryShake.CodeGeneration.CSharp.Integration." + testName;

            if (!File.Exists(testFile))
            {
                File.WriteAllText(
                    testFile,
                    FileResource.Open("TestTemplate.txt")
                    .Replace("{TestName}", testName)
                    .Replace("{Namespace}", ns));
            }

            return(new AssertSettings
            {
                ClientName = testName !+"Client",
                Namespace = ns,
                StrictValidation = true,
                SnapshotFile = System.IO.Path.Combine(
                    snapshotFullName.FolderPath,
                    testName + "Test.Client.cs"),
                RequestStrategy = requestStrategy,
                Profiles = (profiles ?? new [] { TransportProfile.Default }).ToList()
            });
 public async Task EnumValueIsCoercedToListValue()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         {
             heroes(episodes: EMPIRE) {
                 name
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task GetHeroName()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         {
             hero {
                 name
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task Skip_With_Literal(string ifValue)
 {
     Snapshot.FullName(new SnapshotNameExtension(ifValue));
     await ExpectValid($@"
         {{
             human(id: ""1000"") {{
                 name @skip(if: {ifValue})
                 height
             }}
         }}")
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgFieldArgumentExample2()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         {
             human(id: ""1000"") {
                 name
                 height(unit: FOOT)
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task NonNullEnumsSerializeCorrectlyFromVariables()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query getHero($episode: Episode!) {
             hero(episode: $episode) {
                 name
             }
         }",
                       request : r => r.SetVariableValue("episode", "NEW_HOPE"))
     .MatchSnapshotAsync();
 }
示例#10
0
        public async Task DirectiveIntrospection_SomeDirectives_Internal()
        {
            Snapshot.FullName();

            await new ServiceCollection()
            .AddGraphQL()
            .AddDocumentFromString(
                @"
                        type Query {
                            foo: String
                                @foo
                                @bar(baz: ""ABC"")
                                @bar(baz: null)
                                @bar(quox: { a: ""ABC"" })
                                @bar(quox: { })
                                @bar
                        }

                        input SomeInput {
                            a: String!
                        }

                        directive @bar(baz: String quox: SomeInput) repeatable on FIELD_DEFINITION
                    ")
            .UseField(next => next)
            .ModifyOptions(o => o.EnableDirectiveIntrospection = true)
            .AddDirectiveType(new DirectiveType(d =>
            {
                d.Name("foo");
                d.Location(DirectiveLocation.FieldDefinition);
                d.Internal();
            }))
            .ExecuteRequestAsync(
                @"
                        {
                            __schema {
                                types {
                                    fields {
                                        appliedDirectives {
                                            name
                                            args {
                                                name
                                                value
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    ")
            .MatchSnapshotAsync();
        }
        public async Task SkipAllSecondLevelFields()
        {
            Snapshot.FullName();

            await ExpectValid(@"
                query ($if: Boolean!) {
                    human(id: ""1000"")  {
                        name @skip(if: $if)
                    }
                }",
                              request : r => r.SetVariableValue("if", true))
            .MatchSnapshotAsync();
        }
示例#12
0
        public async Task SkipAll_Default_True()
        {
            Snapshot.FullName();

            await ExpectValid(@"
                query ($if: Boolean! = true) {
                    human(id: ""1000"") @skip(if: $if) {
                        name
                        height
                    }
                }")
            .MatchSnapshotAsync();
        }
 public async Task Skip_With_Variable(bool ifValue)
 {
     Snapshot.FullName(new SnapshotNameExtension(ifValue));
     await ExpectValid(@"
         query ($if: Boolean!) {
             human(id: ""1000"") {
                 name @skip(if: $if)
                 height
             }
         }",
                       request : r => r.SetVariableValue("if", ifValue))
     .MatchSnapshotAsync();
 }
 public async Task ConditionalInlineFragment()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         {
             heroes(episodes: [EMPIRE]) {
                 name
                 ... @include(if: true) {
                     height
                 }
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task Ensure_Type_Introspection_Returns_Null_If_Type_Not_Found()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query {
             a: __type(name: ""Foo"") {
                 name
             }
             b: __type(name: ""Query"") {
                 name
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task NonNullListVariableValues()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query op($ep: [Episode!]!)
         {
             heroes(episodes: $ep) {
                 name
             }
         }",
                       request : r => r
                       .SetVariableValue("ep", new ListValueNode(new EnumValueNode("EMPIRE"))))
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgAliasExample()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         {
             empireHero: hero(episode: EMPIRE) {
                 name
             }
             jediHero: hero(episode: JEDI) {
                 name
             }
         }")
     .MatchSnapshotAsync();
 }
        public async Task NestedFragmentsWithNestedObjectFieldsAndSkip()
        {
            Snapshot.FullName();

            await ExpectValid(@"
                query ($if: Boolean!) {
                    human(id: ""1000"") {
                        ... Human1 @include(if: $if)
                        ... Human2 @skip(if: $if)
                    }
                }
                fragment Human1 on Human {
                    friends {
                        edges {
                            ... FriendEdge1
                        }
                    }
                }
                fragment FriendEdge1 on FriendsEdge {
                    node {
                        __typename
                        friends {
                            nodes {
                                __typename
                                ... Human3
                            }
                        }
                    }
                }
                fragment Human2 on Human {
                    friends {
                        edges {
                            node {
                                __typename
                                ... Human3
                            }
                        }
                    }
                }
                fragment Human3 on Human {
                    name
                    otherHuman {
                      __typename
                      name
                    }
                }
                ",
                              request : r => r.SetVariableValue("if", true))
            .MatchSnapshotAsync();
        }
 public async Task Execute_ListWithNullValues_ResultContainsNullElement()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query {
             human(id: ""1001"") {
                 id
                 name
                 otherHuman {
                     name
                 }
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task ExecutionDepthShouldNotLeadToEmptyObjects()
 {
     Snapshot.FullName();
     await ExpectError(@"
         query ExecutionDepthShouldNotLeadToEmptyObjects {
             hero(episode: NEW_HOPE) {
                 __typename
                 id
                 name
                 ... on Human {
                     __typename
                     homePlanet
                 }
                 ... on Droid {
                     __typename
                     primaryFunction
                 }
                 friends {
                     nodes {
                         __typename
                         ... on Human {
                             __typename
                             homePlanet
                             friends {
                                 nodes {
                                     __typename
                                 }
                             }
                         }
                         ... on Droid {
                             __typename
                             primaryFunction
                             friends {
                                 nodes {
                                     __typename
                                 }
                             }
                         }
                     }
                 }
             }
         }",
                       configure : c =>
     {
         AddDefaultConfiguration(c);
         c.AddMaxExecutionDepthRule(3);
     });
 }
 public async Task GraphQLOrgVariableWithDefaultValueExample()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query HeroNameAndFriends($episode: Episode = JEDI) {
             hero(episode: $episode) {
                 name
                 friends {
                     nodes {
                         name
                     }
                 }
             }
         }")
     .MatchSnapshotAsync();
 }
示例#22
0
        public async Task DescriptionsAreCorrectlyRead()
        {
            // arrange
            Snapshot.FullName();
            var source = FileResource.Open("schema_with_multiline_descriptions.graphql");
            var query  = FileResource.Open("IntrospectionQuery.graphql");

            // act & act
            await new ServiceCollection()
            .AddGraphQL()
            .AddDocumentFromString(source)
            .ModifyOptions(o => o.SortFieldsByName = true)
            .UseField(next => next)
            .ExecuteRequestAsync(query)
            .MatchSnapshotAsync();
        }
 public async Task GraphQLOrgOperationNameExample()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query HeroNameAndFriends {
             hero {
                 name
                 friends {
                     nodes {
                         name
                     }
                 }
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgVariableExample()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query HeroNameAndFriends($episode: Episode) {
             hero(episode: $episode) {
                 name
                 friends {
                     nodes {
                         name
                     }
                 }
             }
         }",
                       request : c => c.SetVariableValue("episode", new EnumValueNode("JEDI")))
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgFieldExample()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         {
             hero {
                 name
                 # Queries can have comments!
                 friends {
                     nodes {
                         name
                     }
                 }
             }
         }")
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgInlineFragmentExample2()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query HeroForEpisode($ep: Episode!) {
             hero(episode: $ep) {
                 name
                 ... on Droid {
                     primaryFunction
                 }
                 ... on Human {
                     height
                 }
             }
         }",
                       request : r => r.SetVariableValue("ep", new EnumValueNode("EMPIRE")))
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgDirectiveSkipExample2()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query Hero($episode: Episode, $withFriends: Boolean!) {
             hero(episode: $episode) {
                 name
                 friends @skip(if: $withFriends) {
                     nodes {
                         name
                     }
                 }
             }
         }",
                       request : r => r
                       .SetVariableValue("episode", new EnumValueNode("JEDI"))
                       .SetVariableValue("withFriends", new BooleanValueNode(true)))
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgMutationExample()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         mutation CreateReviewForEpisode(
             $ep: Episode!, $review: ReviewInput!) {
             createReview(episode: $ep, review: $review) {
                 stars
                 commentary
             }
         }",
                       request : r => r
                       .SetVariableValue("ep", new EnumValueNode("JEDI"))
                       .SetVariableValue("review", new ObjectValueNode(
                                             new ObjectFieldNode("stars", new IntValueNode(5)),
                                             new ObjectFieldNode("commentary",
                                                                 new StringValueNode("This is a great movie!")))))
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgDirectiveSkipExample1WithPlainClrVarTypes()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         query Hero($episode: Episode, $withFriends: Boolean!) {
             hero(episode: $episode) {
                 name
                 friends @skip(if: $withFriends) {
                     nodes {
                         name
                     }
                 }
             }
         }",
                       request : r => r
                       .SetVariableValue("episode", "JEDI")
                       .SetVariableValue("withFriends", false))
     .MatchSnapshotAsync();
 }
 public async Task GraphQLOrgMutationExample_With_ValueVariables()
 {
     Snapshot.FullName();
     await ExpectValid(@"
         mutation CreateReviewForEpisode(
             $ep: Episode!
             $stars: Int!
             $commentary: String!) {
             createReview(
                 episode: $ep
                 review: { stars: $stars commentary: $commentary }) {
                 stars
                 commentary
             }
         }",
                       request : r => r
                       .SetVariableValue("ep", new EnumValueNode("JEDI"))
                       .SetVariableValue("stars", new IntValueNode(5))
                       .SetVariableValue("commentary", new StringValueNode("This is a great movie!")))
     .MatchSnapshotAsync();
 }