Skip to content
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

GraphQL Support #399

Open
mrnasil opened this issue May 25, 2024 · 2 comments
Open

GraphQL Support #399

mrnasil opened this issue May 25, 2024 · 2 comments

Comments

@mrnasil
Copy link

mrnasil commented May 25, 2024

Describe the feature

I am wondering if GraphQL support can be added without going into too much detail.

const query = `
  query GetUser($id: ID!) {
    user(id: $id) {
      id
      name
      email
    }
  }
`;

const variables = {
  id: '123',
};

ofetch('https://your-graphql-endpoint.com/graphql', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    query: query,
    variables: variables,
  }),
});


### Additional information

- [ ] Would you be willing to help implement this feature?
@xlanex6
Copy link

xlanex6 commented Jun 23, 2024

Hi @mrnasil

here 's the way I create a basic graphql client in my utils folder

export const $graphqlClient = async (query: string, variables?: object) => {
  const  { data, errors } = await $fetch( ~SERVER_ENDPOINT~, {
    method: 'POST',
    headers: {
      "Content-Type": "application/json",
      "x-secret": ~SECRET-TOKEN~
    },
    body: {
      query,
      variables
    }
  })
  return { data, errors }
}

@mrnasil
Copy link
Author

mrnasil commented Jun 25, 2024

Hi @mrnasil

here 's the way I create a basic graphql client in my utils folder

export const $graphqlClient = async (query: string, variables?: object) => {
  const  { data, errors } = await $fetch( ~SERVER_ENDPOINT~, {
    method: 'POST',
    headers: {
      "Content-Type": "application/json",
      "x-secret": ~SECRET-TOKEN~
    },
    body: {
      query,
      variables
    }
  })
  return { data, errors }
}

"Thank you very much for your response. I also use it in the same way. However, I believe it would be more appropriate for it to be included within ofetch as an optional feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants