refine icon indicating copy to clipboard operation
refine copied to clipboard

[FEAT] add `gqlMutaton` and `gqlQuery` support for graphql data provider

Open alicanerdurmaz opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe.

docs: https://refine.dev/docs/data/packages/graphql/

Currently, the @refinedev/graphql package only supports the meta.fields field for writing queries and mutations. To improve developer experience, @refinedev/graphql should support meta.gqlQuery and metal.gqlMutation

Describe alternatives you've considered

No response

Additional context

The syntax can be like this:

Query Example:

import { useList } from "@refinedev/core";
import gql from "graphql-tag";

const POSTS_LIST_QUERY = gql`
  query PostList($where: JSON, $sort: String) {
    posts(where: $where, sort: $sort) {
      id
      title
      content
      category {
        id
      }
    }
  }
`;

const { data } = useList({
  resource: "posts",
  meta: { gqlQuery: POSTS_QUERY },
});

Mutation Example:

import { useForm } from "@refinedev/core";
import gql from "graphql-tag";

const POST_CREATE_MUTATION = gql`
  mutation createPost($input: createPostInput!) {
    createPost(input: $input) {
      id
      title
      content
      category {
        id
      }
    }
  }
`;

const { formProps } = useForm({
  resource: "posts",
  meta: { gqlMutation: CREATE_POST_MUTATION },
});

Describe the thing to improve

No response

alicanerdurmaz avatar Mar 13 '24 08:03 alicanerdurmaz