houdini icon indicating copy to clipboard operation
houdini copied to clipboard

Refetchable fragments

Open AlecAivazis opened this issue 4 years ago • 2 comments

There should be a @refetchable directive that labels fragments on Node or Query as refetchable. The api could look something like this:

const { data, refetch, variables } = refetchableFragment(graphql`
    fragment UserFragment on User @refetchable @arguments($filter: { type: "String" }) { 
        field(filter: $filter)
    }
`)

const filter = writable("")

$: {
    if ($filter) { 
        refetch({ filter: $filter })
    }
}

AlecAivazis avatar Jul 09 '21 04:07 AlecAivazis

As we have now a Fragment store where we can .get(), we could probably add another function: .refetch() Is there the need to explicitly set @refetchable?

jycouet avatar Jul 17 '22 22:07 jycouet

not every fragment is refetchable, it has to be defined on a type that either extends Node or has a custom type resolution defined. @refetchable would act as a mark to the artifact generator that it needs to generate the appropriate queries and verify the config.

edit: If the queries were computed at runtime, we might be able to do away with it 🤔

AlecAivazis avatar Jul 18 '22 00:07 AlecAivazis