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-tag support for GraphQL Client #1237

Closed
vahdet opened this issue Jul 13, 2018 · 2 comments
Closed

graphql-tag support for GraphQL Client #1237

vahdet opened this issue Jul 13, 2018 · 2 comments
Assignees
Labels
feature-request Request a new feature GraphQL Related to GraphQL API issues

Comments

@vahdet
Copy link

vahdet commented Jul 13, 2018

[Current behavior]
Queries are used as bare strings as shown in official documentation. It just works fine:

import Amplify, { API, graphqlOperation } from "aws-amplify";

const GetEvent = `query GetEvent($id: ID! $nextToken: String) {
    getEvent(id: $id) {
        id
        name
        description
        comments(nextToken: $nextToken) {
            items {
                content
            }
        }
    }
}`;

// Query using a parameter
const oneEvent = await API.graphql(graphqlOperation(GetEvent, { id: 'some id' }));
console.log(oneEvent);

For query declarations, when I want to use graphql-tag as follows:

import Amplify, { API, graphqlOperation } from "aws-amplify";
import gql from "graphql-tag";

// Added 'gql' in front of the string
const GetEvent = gql`query GetEvent($id: ID! $nextToken: String) {
    getEvent(id: $id) {
        id
        name
        description
        comments(nextToken: $nextToken) {
            items {
                content
            }
        }
    }
}`;

// The same query here
const oneEvent = await API.graphql(graphqlOperation(GetEvent, { id: 'some id' }));
console.log(oneEvent);

It breaks down with the error in Developer Console of a browser:

Unhandled promise rejection TypeError: "Must provide Source. Received: [object Object]"

[Requested behavior]

It would be great if graphql-tag is supported to be used as a query in API.graphql(graphqlOperation(...));

@jordanranz jordanranz added feature-request Request a new feature GraphQL Related to GraphQL API issues labels Jul 13, 2018
@samvincent
Copy link

You can do the following for now:

import { print as gqlToString } from 'graphql/language';
...
const oneEvent = await API.graphql(
  graphqlOperation(gqlToString(GetEvent), { id: 'some id' })
);

manueliglesias added a commit to manueliglesias/aws-amplify that referenced this issue Dec 1, 2018
@ghost ghost added the review label Dec 1, 2018
@ghost ghost removed the review label Dec 3, 2018
manueliglesias added a commit that referenced this issue Dec 3, 2018
…nt (#2227)

* feat(@aws-amplify/api,graphql): DocumentNode support for GraphQL Client

Fixes #1237

* Update packages/api/src/API.ts

Co-Authored-By: manueliglesias <manuel.iglesias@gmail.com>
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request a new feature GraphQL Related to GraphQL API issues
Projects
None yet
Development

No branches or pull requests

4 participants