Skip to content

How to update info.field_nodes[0].selection_set ? #135

Closed
@ldynia

Description

@ldynia

Context

I work with graphql in python (graphql-core-3), and I have a GraphQL query that looks like this.

query One {
  library(id: "library_1") {
    name
    book {
      title
      __typename
    }
    __typename
  }
}

When I investigate info object info.field_nodes[0].selection_set.selections I got selection set of FieldNodes that looks like that:

<class 'graphql.language.ast.SelectionSetNode'>
<class 'graphql.pyutils.frozen_list.FrozenList'> [FieldNode at 45:49, FieldNode at 54:95, FieldNode at 100:110]


# FieldNode at 45:49
name

# FieldNode at 54:95
book {
  title
  __typename
}

# FieldNode at 100:110
__typename

Problem

In my second query set I added results field to wrap my data.

query All {
  allLibrary {
    results {
      name
      book {
        title
        __typename
      }
      __typename
    }
    __typename
  }
}

Unfortunately, this causes a problem because query set is resolved from level of allLibrary not library as in the first example. The consequences of this structure is that info.field_nodes[0].selection_set.selections resolves fields incorrectly. Skiping, all the fields that I have interest in (name , book, __typename).

<class 'graphql.language.ast.SelectionSetNode'>
<class 'graphql.pyutils.frozen_list.FrozenList'> [FieldNode at 14:147, FieldNode at 133:143] 

# FieldNode at 31:128
results {
  name
  book {
    title
    __typename
  }
  __typename
}

# FieldNode at 133:143
__typename

Question

How I can fix my info.field_nodes[0].selection_set so it fetches the FieldNode correctly ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions