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.

Cannot use DataFetcherResult as an item for GraphQL List fields

See original GitHub issue

Library Version What version are you using? 4.1.1

Describe the bug A clear and concise description of what the bug is. GraphQL-Java supports using DataFetcherResult as an item for list fields with this PR, which is useful for providing local context for individual items in lists (see this issue).

However, graphql-kotlin’s schema generator throws a TypeNotSupportedException when it is provided as a return type for a resolver:

com.expediagroup.graphql.generator.exceptions.TypeNotSupportedException: Cannot convert graphql.execution.DataFetcherResult<mypackage.EntityType> since it is not a valid GraphQL type or outside the supported packages "[mypackage.graphql]"

To Reproduce Steps to reproduce the behavior. Please provide:

  • Schema Configuration
graphql:
  packages:
    - "mypackage.graphql"

(no other config)

  • Kotlin code used to generate the schema
data class WorldType(
    private val world: World
) {
  fun entities(
      dataFetchingEnvironment: DataFetchingEnvironment
  ): List<DataFetcherResult<EntityType>> = world.entities.map {
      DataFetcherResult.newResult<EntityType>()
          .data(it)
          .localContext(dataFetchingEnvironment.getLocalContext<LocalContext>()?.copy(
              currentEntityId = it.entityId
          ))
          .build()
  }
}

Expected behavior A clear and concise description of what you expected to happen.

There should be no TypeNotSupportedException thrown, as this configuration is supported by graphql-java and requires no type mapping by graphql-kotlin.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
teoboleycommented, May 15, 2021

I’ve created a PR with the change for review: https://github.com/ExpediaGroup/graphql-kotlin/pull/1150

0reactions
teoboleycommented, May 14, 2021

Sorry, EntityType is actually under mypackage.graphql, I had just changed out the package names for the sake of the example, it is not causing the error - the List<> wrapping of DataFetcherResult is

Read more comments on GitHub >

github_iconTop Results From Across the Web

Individual localContexts for entries in List · Issue #1559 - GitHub
DataFetcherResult } or in a List of {@link graphql.execution. ... Allow and process DataFetcherResult as an item for GraphQL List fields.
Read more >
Execution - GraphQL Java
How to execute a query using the graphql-java engine. ... information such as the field's parent object, the query root object or the...
Read more >
DataFetchingEnvironment (graphql-java 0.0.0-2021-07-18T08 ...
This returns a context object that parent fields may have returned returned via DataFetcherResult.getLocalContext() which can be used to pass down extra ...
Read more >
Nested data fetchers - DGS Framework
Commonly, the datafetcher for a nested field requires properties from its parent object to load its data. Take the following schema example.
Read more >
GraphQL Java custom scalar type for map is not accepted by ...
I can not find any hind in the tutorials to find out what I am missing out to make it work. I understand...
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