Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Generic wrapper don't work with Lists

オープン
#254 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
graphql, java, kotlin
領域
api, backend

調査の方向性

Start with the source resolver in FieldResolver.kt, named in the stack trace, and reproduce the supplied example with List<Try<Payload>>. Compare it with the working Try<Payload> case; done means nested wrappers resolve the Payload fields instead of passing the Try object to field resolution.

索引モデルが issue の本文から書いたものです。

説明

bug

Generic wrappers don't work if used not as outermost wrapper, i.e. Wrapper<String> works while List<Wrapper<String>> doesn't.

My example, with Vavr Try:

package com.my.test;

import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.coxautodev.graphql.tools.SchemaParser;
import com.coxautodev.graphql.tools.SchemaParserOptions;
import graphql.GraphQL;
import io.vavr.control.Try;

import java.util.List;

public class GenericWrapperTest {

    private static final String schemaString = "type Query {\n" +
            "    payloads: [Payload!]!\n" +
            "}\n" +
            "\n" +
            "type Payload {\n" +
            "    data: String!\n" +
            "}";

    private static final String query = "{\n" +
            "    payloads {\n" +
            "        data\n" +
            "    }\n" +
            "}";

    public static class Payload {
        public Try<String> getData() {
            return Try.success("foo");
        }
    }

    public static class Query implements GraphQLQueryResolver {
        public List<Try<Payload>> getPayloads() {
            return List.of(Try.success(new Payload()));
        }
    }

    public static void main(String[] args) {

        final var tryWrapper = SchemaParserOptions.GenericWrapper.withTransformer(io.vavr.control.Try.class, 0,
                Try::get, type -> type);


        final var schema = SchemaParser.newParser()
                .schemaString(schemaString)
                .resolvers(new Query())
                .options(SchemaParserOptions.newOptions()
                        .genericWrappers(tryWrapper)
                        .build())
                .build()
                .makeExecutableSchema();

        System.out.println(GraphQL.newGraphQL(schema).build().execute(query));

    }
}

Trying to run this results in

2019-03-28 14:11:35.212 [main] WARN  g.e.SimpleDataFetcherExceptionHandler:23 - Exception while fetching data (/payloads[0]/data) : Expected source object to be an instance of 'com.my.test.GenericWrapperTest$Payload' but instead got 'io.vavr.control.Try$Success'
com.coxautodev.graphql.tools.ResolverError: Expected source object to be an instance of 'com.my.test.GenericWrapperTest$Payload' but instead got 'io.vavr.control.Try$Success'
	at com.coxautodev.graphql.tools.FieldResolver$getSourceResolver$2.invoke(FieldResolver.kt:27)

Switching payloads to just Try<Payload> makes it run as expected - fail field resolution on failed Try and complete on successful.

主要言語
Kotlin
スター
824
フォーク
175
平均マージ
2日 5時間
マージ済み PR(30日)
52

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

graphql-java-kickstart/graphql-java-tools のほかの issue

graphql-java-kickstart/graphql-java-tools の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。