Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue]: Client fails to build when calling a GraphQL operation with an @internal directive from a TS Operation #1373

Closed
RayHughes opened this issue Mar 7, 2024 · 1 comment

Comments

@RayHughes
Copy link
Contributor

Description

When calling a GraphQL operation with an internal directive from a TS operation, the client falls to build.

DTS Build start
../.wundergraph/operations/v1/content/articles/RelatedBySlug.ts(17,7): error TS2741: Property 'username' is missing in type '{ category: string; page: number | undefined; pageSize: number | undefined; slug: string; }' but required in type 'V1ContentArticlesByCategoryAndSlugFilterInputInternal'.

Error: error occured in dts build
    at Worker.<anonymous> (/Users/ray/Desktop/Projects/graph/client/node_modules/tsup/dist/index.js:2294:26)
    at Worker.emit (node:events:514:28)
    at MessagePort.<anonymous> (node:internal/worker:263:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:778:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)
DTS Build error
RollupError: Failed to compile. Check the logs above.
    at error (/Users/ray/Desktop/Projects/graph/client/node_modules/rollup/dist/shared/rollup.js:349:30)
    at Object.error (/Users/ray/Desktop/Projects/graph/client/node_modules/rollup/dist/shared/rollup.js:1715:20)
    at Object.error (/Users/ray/Desktop/Projects/graph/client/node_modules/rollup/dist/shared/rollup.js:25438:42)
    at generateDtsFromTs (/Users/ray/Desktop/Projects/graph/client/node_modules/tsup/dist/rollup.js:7512:22)
    at /Users/ray/Desktop/Projects/graph/client/node_modules/tsup/dist/rollup.js:7519:59
    at _nullishCoalesce (/Users/ray/Desktop/Projects/graph/client/node_modules/tsup/dist/rollup.js:1:198)
    at Object.transform (/Users/ray/Desktop/Projects/graph/client/node_modules/tsup/dist/rollup.js:7519:18)
    at /Users/ray/Desktop/Projects/graph/client/node_modules/rollup/dist/shared/rollup.js:1908:40

TS Operation

    const articles = await operations.query({
      operationName: 'v1/content/articles/internal/ByCategoryAndSlugFilter',
      input: {
        category: category.toString(),
        page: input?.page,
        pageSize: input?.pageSize,
        slug,
      }
    })

GraphQL Operation

query ByCategoryAndSlugFilter ($page: Int! = 1, $pageSize: Int! = 25, $slug: String!, $category: String!, $username: String! @internal) {
    articles: sharpContent_articles(
        publicationState: LIVE,
        sort: "articleDate:desc"
        pagination: {
            page: $page,
            pageSize: $pageSize
        },
        filters: {
            slug: { notContainsi: $slug }
            or: [
                { category: { slug: { eqi: $category } }},
                { tags: { slug: { eqi: $category } }}
            ]
        }
    ) {
        data {
            attributes {
                author {
                    data {
                        attributes {
                            name
                            username @export(as: "username")
                            avatarUrl: _join @transform(get: "sharpApi_getUserAvatar.avatarUrl") {
                                sharpApi_getUserAvatar(username: $username) {
                                    avatarUrl
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

It appears that it is expecting the username to be passed through to the GraphQL operation despite it being an internal directive.

Adding an input with an empty string to match the directive works around the issue and it functions as desired:

    const articles = await operations.query({
      operationName: 'v1/content/articles/internal/ByCategoryAndSlugFilter',
      input: {
        category: category.toString(),
        page: input?.page,
        pageSize: input?.pageSize,
        slug,
        username: ''
      }
    })

Reproduction

  1. Create a TS operation that calls a GraphQL operation
  2. Add a join / internal directive to the GraphQL operation
  3. Generate the client
Copy link

stale bot commented May 6, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale label May 6, 2024
@stale stale bot closed this as completed May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant