<commit_before>package graphql

import spock.lang.Specification

class StarWarsQueryTest extends Specification {

    def 'Correctly identifies R2-D2 as the hero of the Star Wars Saga'() {
        given:
        def query = """
        query HeroNameQuery {
          hero {
            name
          }
        }
        """
        def expected = [
                hero: [
                        name: 'R2-D2'
                ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected
    }


    def 'Allows us to query for the ID and friends of R2-D2'() {
        given:
        def query = """
        query HeroNameAndFriendsQuery {
            hero {
                id
                name
                friends {
                    name
                }
            }
        }
        """
        def expected = [
                hero: [
                        id     : '2001',
                        name   : 'R2-D2',
                        friends: [
                                [
                                        name: '<NAME>',
                                ],
                                [
                                        name: '<NAME>',
                                ],
                                [
                                        name: '<NAME>',
                                ],
                        ]
                ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected
    }

    def 'Allows us to query for the friends of friends of R2-D2'() {
        given:

        def query = """
        query NestedQuery {
            hero {
                name
                friends {
                    name
                    appearsIn
                    friends {
                        name
                    }
                }
            }
        }
        """
        def expected = [
                hero: [name   : 'R2-D2',
                       friends: [
                               [
                                       name     :
                                               '<NAME>',
                                       appearsIn: ['NEWHOPE', 'EMPIRE', 'JEDI'],
                                       friends  : [
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: 'C-3PO',
                                               ],
                                               [
                                                       name: 'R2-D2',
                                               ],
                                       ]
                               ],
                               [
                                       name     : '<NAME>',
                                       appearsIn: ['NEWHOPE', 'EMPIRE', 'JEDI'],
                                       friends  : [
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: 'R2-D2',
                                               ],
                                       ]
                               ],
                               [
                                       name     : '<NAME>',
                                       appearsIn: ['NEWHOPE', 'EMPIRE', 'JEDI'],
                                       friends  : [
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: 'C-3PO',
                                               ],
                                               [
                                                       name: 'R2-D2',
                                               ],
                                       ]
                               ],
                       ]
                ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected


    }

    def 'Allows us to query for <NAME> directly, using his ID'() {
        given:
        def query = """
        query FetchLukeQuery {
            human(id: "1000") {
                name
            }
        }
        """
        def expected = [
                human: [
                        name: '<NAME>'
                ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected
    }

    def 'Allows us to create a generic query, then use it to fetch <NAME> using his ID'() {
        given:
        def query = """
        query FetchSomeIDQuery(\$someId: String!) {
            human(id: \$someId) {
                name
            }
        }
        """
        def params = [
                someId: '1000'
        ]
        def expected = [
                human: [
                        name: '<NAME>'
                ]
        ]
        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query, params).execute()

        then:
        result == expected
    }


    def 'Allows us to query for Luke, changing his key with an alias'() {
        given:
        def query = """
            query FetchLukeAliased {
                luke: human(id: "1000") {
                    name
                }
            }
        """
        def expected = [
                luke: [
                        name: '<NAME>'
                ],
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected
    }

}<commit_msg>another star wars query test<commit_after>package graphql

import spock.lang.Specification

class StarWarsQueryTest extends Specification {

    def 'Correctly identifies R2-D2 as the hero of the Star Wars Saga'() {
        given:
        def query = """
        query HeroNameQuery {
          hero {
            name
          }
        }
        """
        def expected = [
                hero: [
                        name: 'R2-D2'
                ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected
    }


    def 'Allows us to query for the ID and friends of R2-D2'() {
        given:
        def query = """
        query HeroNameAndFriendsQuery {
            hero {
                id
                name
                friends {
                    name
                }
            }
        }
        """
        def expected = [
                hero: [
                        id     : '2001',
                        name   : 'R2-D2',
                        friends: [
                                [
                                        name: '<NAME>',
                                ],
                                [
                                        name: '<NAME>',
                                ],
                                [
                                        name: '<NAME>',
                                ],
                        ]
                ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected
    }

    def 'Allows us to query for the friends of friends of R2-D2'() {
        given:

        def query = """
        query NestedQuery {
            hero {
                name
                friends {
                    name
                    appearsIn
                    friends {
                        name
                    }
                }
            }
        }
        """
        def expected = [
                hero: [name   : 'R2-D2',
                       friends: [
                               [
                                       name     :
                                               '<NAME>',
                                       appearsIn: ['NEWHOPE', 'EMPIRE', 'JEDI'],
                                       friends  : [
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: 'C-3PO',
                                               ],
                                               [
                                                       name: 'R2-D2',
                                               ],
                                       ]
                               ],
                               [
                                       name     : '<NAME>',
                                       appearsIn: ['NEWHOPE', 'EMPIRE', 'JEDI'],
                                       friends  : [
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: 'R2-D2',
                                               ],
                                       ]
                               ],
                               [
                                       name     : '<NAME>',
                                       appearsIn: ['NEWHOPE', 'EMPIRE', 'JEDI'],
                                       friends  : [
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: '<NAME>',
                                               ],
                                               [
                                                       name: 'C-3PO',
                                               ],
                                               [
                                                       name: 'R2-D2',
                                               ],
                                       ]
                               ],
                       ]
                ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected


    }

    def 'Allows us to query for <NAME> directly, using his ID'() {
        given:
        def query = """
        query FetchLukeQuery {
            human(id: "1000") {
                name
            }
        }
        """
        def expected = [
                human: [
                        name: '<NAME>'
                ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected
    }

    def 'Allows us to create a generic query, then use it to fetch <NAME> using his ID'() {
        given:
        def query = """
        query FetchSomeIDQuery(\$someId: String!) {
            human(id: \$someId) {
                name
            }
        }
        """
        def params = [
                someId: '1000'
        ]
        def expected = [
                human: [
                        name: '<NAME>'
                ]
        ]
        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query, params).execute()

        then:
        result == expected
    }


    def 'Allows us to query for Luke, changing his key with an alias'() {
        given:
        def query = """
            query FetchLukeAliased {
                luke: human(id: "1000") {
                    name
                }
            }
        """
        def expected = [
                luke: [
                        name: '<NAME>'
                ],
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected
    }

    def 'Allows us to query for both Luke and Leia, using two root fields and an alias'() {
        given:

        def query = """
        query FetchLukeAndLeiaAliased {
            luke:
            human(id: "1000") {
                name
            }
            leia:
            human(id: "1003") {
                name
            }
        }
        """
        def expected = [
                luke:
                        [
                                name: '<NAME>'
                        ],
                leia:
                        [
                                name: '<NAME>'
                        ]
        ]

        when:
        def result = new GraphQL(StarWarsSchema.starWarsSchema, query).execute()

        then:
        result == expected

    }
}
{'fraction_non_alphanumeric': 0.07433468022850773, 'fraction_numerical': 0.005573359342343598, 'mean_word_length': 0.46599264705882354, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 172, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7652786', 'n_tokens_mistral': 2803, 'n_tokens_neox': 2615, 'n_words': 615}