示例#1
0
    def test_with_fragments(self):
        self.assertEqual(
            self.parser.parse("""
                query withNestedFragments {
                  user(id: 4) {
                    friends(first: 10) {
                      ...friendFields
                    }
                    mutualFriends(first: 10) {
                      ...friendFields
                    }
                  }
                }

                fragment friendFields on User {
                  id
                  name
                  ...standardProfilePic
                }

                fragment standardProfilePic on User {
                  profilePic(size: "small")
                }
            """),
            Document(definitions=[
                Query(
                    name='withNestedFragments',
                    selections=[
                        Field(selections=[
                            Field(selections=[
                                FragmentSpread(name='friendFields')
                            ],
                                  name='friends',
                                  arguments=[Argument(name='first', value=10)
                                             ]),
                            Field(selections=[
                                FragmentSpread(name='friendFields')
                            ],
                                  name='mutualFriends',
                                  arguments=[Argument(name='first', value=10)])
                        ],
                              name='user',
                              arguments=[Argument(name='id', value=4)])
                    ]),
                FragmentDefinition(type_condition=NamedType(name='User'),
                                   name='friendFields',
                                   selections=[
                                       Field(name='id'),
                                       Field(name='name'),
                                       FragmentSpread(
                                           name='standardProfilePic')
                                   ]),
                FragmentDefinition(
                    type_condition=NamedType(name='User'),
                    name='standardProfilePic',
                    selections=[
                        Field(name='profilePic',
                              arguments=[Argument(name='size', value='small')])
                    ])
            ]))
示例#2
0
    def test_shorthand_query_with_fragments(self):
        self.assertEqual(
            self.parser.parse("""
                {
                  hero {
                    name
                    ...DroidFields
                  }
                }

                fragment DroidFields on Droid {
                  primaryFunction
                }
            """),
            Document(definitions=[
                Query(selections=[
                    Field(name='hero',
                          selections=[
                              Field(name='name'),
                              FragmentSpread(name='DroidFields'),
                          ]),
                ]),
                FragmentDefinition(type_condition=NamedType(name='Droid'),
                                   name='DroidFields',
                                   selections=[Field(name='primaryFunction')]),
            ]))