fix for #124 is incomplete

Đang mở
#334 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu với com.netflix.graphql.dgs.client.codegen.InputValueSerializer và GraphQLQueryRequest.serialize, sau đó xem xét commit kiểm thử bị lỗi được liên kết và các quy tắc literal chuỗi của GraphQL October 2021. Tái hiện các ví dụ chứa ký tự xuống dòng về đầu dòng, null và các ký tự điều khiển bằng thiết lập client codegen. Được xem là hoàn tất khi các truy vấn đã serialize được phân tích cú pháp thành công đối với các trường hợp này và các kiểm thử liên quan bao quát hành vi escaping.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

What happened

The com.netflix.graphql.dgs.client.codegen.InputValueSerializer from com.netflix.graphql.dgs.codegen:graphql-dgs-codegen-client-core:5.1.16 did not emit a GraphQL compliant string literal causing the server to which the request was sent to error while trying to parse the GraphQL query

How to reproduce it

  1. Create a schema1.graphqls as below
  2. Use the codegen plugin with generateClient = true
  3. Create a driver class as show below
  4. Observe the parse error when parsing the return from .serialize

I have a failing test, too, although it was just some "hello world" failures, and does not attempt to enumerate all of the missing edge cases

Samples

schema1.graphqls
input PersonInput {
  name: String
}
type Person {
    name: String
}
type Query {
    friends(like: PersonInput): Person
}
Driver.java
package com.example;

import com.example.gql.client.FriendsGraphQLQuery;
import com.example.gql.client.FriendsProjectionRoot;
import com.example.gql.types.PersonInput;
import com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest;
import graphql.parser.Parser;

public class Driver {
    public static void main(String[] args) {
        final var names = new String[] {
                // but unicode is already correct
                "💣",
                "\r\n",
                "\u0000",
                "\u001F",
        };
        for (var name : names) {
            final String gql = new GraphQLQueryRequest(
                    FriendsGraphQLQuery.newRequest()
                            .like(PersonInput.newBuilder()
                                    .name(name)
                                    .build())
                            .build(),
                    new FriendsProjectionRoot().name()
            ).serialize();
            System.out.printf("gql = <<%s>>%n", gql);
            var doc = Parser.parse(gql);
            System.out.println("doc = " + doc);
        }
    }
}

What was expected

GraphQLQueryRequest.serialize should return legal GraphQL query text

Versions

  • id("com.netflix.dgs.codegen") version "5.1.16"
  • implementation("com.netflix.graphql.dgs:graphql-dgs-client:4.9.16")

Workaround

In case someone else stumbles upon this issue, I have a work-around until it is fixed: supersede the scalars parameter and register a JSON-safe graphql.scalar.GraphqlStringCoercing:

            final Map<Class<?>, Coercing<?, ?>> scalars = Map.of(String.class, new GraphqlStringCoercing() {
                @Override
                public String serialize(final Object input) {
                    final var s = (String) input;
                    // this one was chosen because dgs-client uses it, 
                    // meaning it will be present everywhere GraphQLQueryRequest is
                    return net.minidev.json.JSONValue.escape(s);
                }
            });
            final String gql = new GraphQLQueryRequest(
                    FriendsGraphQLQuery.newRequest()
                            .like(PersonInput.newBuilder()
                                    .name(name)
                                    .build())
                            .build(),
                    new FriendsProjectionRoot().name(),
                    scalars
            ).serialize();
            // and now gql will parse successfully
Ngôn ngữ chính
Kotlin
Star
220
Fork
123
Merge trung bình
1 ngày 6 giờ
Pull request đã merge (30 ngày)
23

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Netflix/dgs-codegen

Tất cả issue của Netflix/dgs-codegen

Issue tương tự

Thêm issue về Kotlin

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.