Hello - I've got this query with some default values:
export const ALL_ITEMS_QUERY = gql`
query AllLinksQuery($skip: Int = 6, $first: Int = 3) {
_allItemsMeta {
count
}
allItems(orderBy: createdAt_DESC, first: $first, skip: $skip) {
id,
title
}
}
`
Now on page load I run it like this:
const itemsEnahncer = graphql(ALL_ITEMS_QUERY, { name: 'allItemsQuery' });
and the causes the variables $first and $skip to be sent as null, which isn't enough for a graphql server to kick in the default values.
Now if I explicitly pass the values as undefined, the default values of the query kick in.
const itemsEnahncer = graphql(ALL_ITEMS_QUERY, { name: 'allItemsQuery', options: {
// TODO: This is funny, I should be able to omit this all together
variables: { first: undefined, skip: undefined }
}});
Is this a bug? Or am I doing something wrong?
"react-apollo": "^1.4.14",
@wesbos it is a bug, though I'm not sure if in this library of the core client. I'll take a look!
This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!
@jbaxleyiii,
This still seems to be an issue. When passing undefined in a top-level variables, Apollo Client will convert it to null.
This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!
This issue has been automatically closed because it has not had recent activity after being marked as no recent activyt. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to React Apollo!
Is this still an issue @jbaxleyiii? Or is it gone in Apollo Client 2.0?
I can confirm that this still happening in Apollo Client 2.0 (I'm using v2.2.5).
We're still seeing this behavior in Apollo Client 2.1.
@jbaxleyiii Would it be okay to re-open this ticket? It's counter-intuitive that default arguments in our Express server are not triggered by the nulls vs. the undefineds.
It is still an issue in Apollo Client 2.1.
In versions 1.x the problem was in this function:
https://github.com/apollographql/react-apollo/blob/v1.4.15/src/graphql.tsx#L276
If the variables were passed they would be used as is, if the variables were extracted from props the undefined values were replaced by nulls:
if (typeof props[variable.name.value] !== 'undefined') {
variables[variable.name.value] = props[variable.name.value];
continue;
}
// allow optional props
if (type.kind !== 'NonNullType') {
variables[variable.name.value] = null;
continue;
}
I'm still seeing this issue with Apollo Client v2.5.1. Is there a workaround for this?
Same here with 2.6.4, maybe repoen this?
I am also having this issue in 3.1.3
Most helpful comment
I'm still seeing this issue with Apollo Client v2.5.1. Is there a workaround for this?