HoudiniGraphql / houdini

The disappearing GraphQL framework
http://www.houdinigraphql.com
MIT License
913 stars 99 forks source link

Cannot have _insert list fragments with subfields that have required arguments that depend on variables #1346

Closed ewen-lbh closed 2 weeks ago

ewen-lbh commented 2 months ago

Describe the bug

Hi, just stumbled upon this today.

Take the following list fragment declaration:

# in a query that defines $uid
    contributionOptions @list(name: "List_UserContributions_Options") {
      canMarkAsPaid
      paidByUser: paidBy(uid: $uid)
      localID
      ...ItemContribution
    }

and the following mutation:

    mutation DeleteContribution($user: UID!, $option: LocalID!) {
      deleteContribution(user: $user, option: $option) {
        ...MutationErrors
        ... on MutationDeleteContributionSuccess {
          data {
            ...List_UserContributions_Pending_remove
            ...List_UserContributions_Paid_remove
            ...List_UserContributions_Options_insert
          }
        }
      }
    }

The runtime tries to fetch the paidBy field without giving it a value when calling .mutate on that mutation store.

I guess the codegen should not generate _insert fragments that define fields that depend on variables.

Or maybe define those variables on the fragment and require giving them values with @with. i guess the library user cannot use @arguments on @list ? if they can, maybe this should also be enforced by the codegen

The "repro link" is a gist of the full graphql request as sent by the runtime when calling .mutate. The gist also has a link to the schema (I tried copy-pasting it in the gist and my browser freezed lmao)

Reproduction

https://gist.github.com/ewen-lbh/bc2d092cbf48b5f720f5c02026095e4a

Workaround

In the meantime, I'm kind of "manually" marking the cached data as stale and re-fetching:

  cache.markStale('User', {
    field: 'contributionOptions',
  });
  await new PageUserEditContributionsStore().fetch({
    variables: { uid: by },
  });
SeppahBaws commented 2 months ago

I ran into the same issue a while back at work. I solved it after some troubleshooting by adding a @with on the _insert fragment spread.

Maybe we could add a step in the codegen pipeline that throws an error when list inserts require arguments, so that it's clear what's going on?

AlecAivazis commented 2 weeks ago

I'm going to close this sicne there is a work around.