babyfish-ct / graphql-ts-client

Typescript DSL for GraphQL.
MIT License
147 stars 20 forks source link

Cannot stringify nested input arguments #14

Closed VojtaStanek closed 2 years ago

VojtaStanek commented 2 years ago

This code:

execute(mutation$.upsertIssue(
    {
        by: {
            year: 2022,
            issue: 19,
        },
        create: {
            title: "A",
            subtitle: "B",
        },
        update: {
            title: "A",
            subtitle: "B",
        },
    },
    issueUpsertResult$.ok.errorMessage,
))

Results in the following query

mutation {
        upsertIssue(
                by: ,
                "year": 2022,
                "issue": 19,
                create: ,
                "title": "A",
                "subtitle": "B",
                update: ,
                "title": "A",
                "subtitle": "B"
        ) {
                ok
                errorMessage
        }
}

Expected mutation:

mutation {
        upsertIssue(
                by: { "year": 2022, "issue": 19 },
                create: { "title": "A", "subtitle": "B" },
                update: { "title": "A", "subtitle": "B" },
        ) {
                ok
                errorMessage
        }
}
babyfish-ct commented 2 years ago

I reproduced.

This is a bug, although it's not recommended style: hard code style. execute(mutation$.doSomething({...blalba...}, fetcher));

You should use the more recommended code: parameterized style execute( mutation$.doSomething(fetcher), { variables: {...blalba...} } );

Parameterized style can run successful, so you can continue your job. In fact you should always use parameterized style.

Even if I fix this bug in the future to make hardcoded style can work, please don't use the hardcoded style.

babyfish-ct commented 2 years ago

3.0.17 is released.

You can use hardcode style code to validate it again. If it works, please close this issue.

Remember, even if this issue has been resolved, please don't use hardcode style in your real projects.

VojtaStanek commented 2 years ago

This works very well! Thanks a lot for the quick response!