-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[BUG] getOne method doesn't use meta.gqlVariables
in @refinedev/hasura
#6374
Comments
I am trying to do something more simple like this and it still doesnt work it only passes the ID, nothing changes there is no extraValue. const { data, isLoading, isError } = useOne({
resource: "settings",
id: 1,
meta: {
gqlQuery: SETTINGS_WITH_VALUES_DATA_QUERY,
variables: {
extraValue: 2,
},
gqlVariables: {
extraValue: 2,
},
},
queryOptions: {
enabled: true,
},
}); Inside my DataProvider i have this: getOne: async (...args) => {
try {
return await dataProvider.getOne(...args);
} catch (error) {
throw error;
}
}, I managed to pass variables by changing it to this: getOne: async ({ resource, id, meta }) => {
try {
// Extract custom variables from meta
const customVariables = meta?.variables || {};
const variables = {
id,
...customVariables,
};
const query = meta?.gqlQuery!;
const response = await client.request<BaseRecord>(query, variables);
return {
data: response[meta?.operation!],
};
} catch (error) {
throw error;
}
}, But is this correct? I dont want to write custom logic for something that already exists like passing a custom varaible? |
Hey @vrrashkov sorry for the issue! Looks like the PR #6222 missed updating the We'll be happy to see your contribution, if you can prepare a PR with the fix. Until this is fixed and released, you can stick with your workaround for the I'll update the issue title since this is not related with |
meta.gqlVariables
in @refinedev/hasura
Hey, i tried the new version with the fix, updated to this version
|
Hey @vrrashkov can you try passing 2nd parameter, https://github.com/refinedev/refine/blob/master/packages/graphql/src/dataProvider/options.ts |
Hey, I have not tried to check the getOne approach because my main uses are from useForm like this, I do not see buildVariables parameter there const { formProps: editFormProps, saveButtonProps: editSaveButtonProps } =
useForm<
GetFields<UpdateSettingValueMutation>,
HttpError,
GetVariables<UpdateSettingValueMutationVariables>
>({
action: "edit",
resource: "settings",
id: editingId?.toString(),
meta: {
gqlQuery: SETTINGS_WITH_VALUES_DATA_QUERY,
gqlMutation: UPDATE_SETTING_VALUES_MUTATION,
gqlVariables: {
environmentId: parseInt(environment.id),
},
variables: {
environmentId: parseInt(environment.id),
},
},
queryMeta: {
variables: {
environmentId: parseInt(environment.id),
},
},
queryOptions: {
enabled: !!editingId,
},
mutationMode: "pessimistic",
onMutationSuccess: () => {
setEditingId(null);
},
});`
EDIT: I see that the provider there is different than what i am using so will try to change that and get back to you if it works. |
@BatuhanW I changed the provider to use urql and now this works as expected. Also this provider look much easier to work with than what i had before :D Thank you!
|
Describe the bug
Trying to pass custom variables other than ID to a query is not working. Here is the code that I have. I am using useForm and what in my getOne query to have extra variable not only the ID.
My graphql is this:
I am not sure if I am missing something from the documentation but i have tried multiple ways as you can see in the above code and nothing seems to be helping it always sends only
variables : {id: "1"}
, the extraValue i am trying to pass its not there.Steps To Reproduce
Test with the code provided
Expected behavior
Custom variables should be included
Packages
Additional Context
No response
The text was updated successfully, but these errors were encountered: