question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting connection fields within DataFetcher#get

See original GitHub issue

Hello mates, What is the best way to get the list of fields from nodes and edges.node in my DataFetcher for ThingConnection? I need the union of these fields to make an optimal fetch to my datastore I was able to get them when the query didn’t include fragments, using env.getSelectionSet and walking through the fields

// I notice that this hack gets me fields at top level in my graphql.schema.DataFetcher#get ThingConnection implementation
DataFetchingFieldSelectionSetImpl ss = ((DataFetchingFieldSelectionSetImpl) ((DataFetchingEnvironmentImpl) env).selectionSet);
ss.fieldCollector.collectFields(ss.parameters,ss.fields)

What would be the best way to go deeper into the tree without having to expand the fragments and evaluating skip/include directives. If this facility is not in place would you consider adding a convenience method for this case?

Type definition

# A connection to a list of Things.
type ThingConnection {
  # Information to aid in pagination.
  pageInfo: PageInfo

  # A list of Things.
  nodes: [Thing]

  # A list of Thing edges.
  edges: [ThingEdge]

  # Count of filtered result set without considering pagination arguments.
  totalCount: Int!
}

query

{
  things(first: 10) {
    nodes {
      ... thingInfo @skip(if:false)
      ...fix
    }
    edges {
      cursor
      node {
        description
        status {
          ...status @skip(if:false)
        }
      }
    }
    totalCount
  }
}

fragment thingInfo on Thing {
  key
  summary
  status {
    ...status
  }
}

fragment fix on Thing {
  stuff  {
    name
  }
}

fragment status on Status {
  name
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
andimarekcommented, Aug 30, 2018
1reaction
bbakermancommented, Aug 16, 2018

I was thinking something like this (psudeo java)

class SelectedFieldAndType {
     String fieldName
     GraphqlType fieldType
     List<FieldAndType> subSelection()
}

List<SelectedFieldAndType> selectedFields = dataFetchingFieldSelectionSet.getSelectionFor("node")

Maybe this would help build a tree structure of subselected fields and their types.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL register new Type wiring with argument to data fetcher
Inside data fetcher get field name from DataFetcherEnvironment. Use reflection to get field from source object. Example #1: RuntimeWiring.
Read more >
Data fetching - DGS Framework - Netflix Open Source
The DgsDataFetchingEnvironment gives access to the context , the query itself, data loaders, and the source object. The source object is the object...
Read more >
Data Consolidation for Data Sources of Non- uniform Sample ...
As becomes apparent in Figure 2, we simply get rid of certain samples in the discrete- time signal. ... var backendUrl = '/data-fetcher/get-....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found