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

Compiler: warn about missing/invalid directives #4776

Open
MarceloPrado opened this issue Aug 28, 2024 · 0 comments
Open

Compiler: warn about missing/invalid directives #4776

MarceloPrado opened this issue Aug 28, 2024 · 0 comments

Comments

@MarceloPrado
Copy link

When writing an inline fragment to be used by readInlineData, Relay won't warn you if you forget to use the @inline directive:

export function getFooBarValue(fragmentRef: DummyExampleFragment$key) {
  const data = readInlineData(
    graphql`
      fragment DummyExampleFragment on Node {
        ... on Foo {
          bar
        }
      }
    `,
    fragmentRef,
  );

  return data?.foo?.bar ?? "";
}

From the compiler standpoint, everything works great as long as you spread DummyExampleFragment on Node. However, at runtime, Relay will throw an error:

Invariant Violation: GraphQLTag: Expected an inline data fragment, got `{"argumentDefinitions": ... }`.

The fix is simple - we just need to add @inline to our fragment definition. It would be great if the compiler explained that to me at build-time.

Overall, I believe we need "smarter" fragment types. Typescript should complain if:

  • I pass a fragment without @refetchable to useRefetchableFragment
  • I pass a fragment without @inline to readInlineData
  • I pass a fragment without @connection and @refetchable to usePaginationFragment
  • etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant