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

networkInterface return an object rather than string for GraphQLRequest.query #637

Closed
linonetwo opened this issue Sep 13, 2016 · 3 comments

Comments

@linonetwo
Copy link

linonetwo commented Sep 13, 2016

As #379 ,

The query receive from ApolloClient is mismatching the second argument of graphql( ) , because query is now an Object {kind: "Document", definitions: Array[1]} .

But as document read query is just a string.
I tried to remove addQueryMerging( ) and

queryTransformer: addTypename,
shouldBatch: true,

from new ApolloClient({ })
but query still being an object.

@linonetwo
Copy link
Author

linonetwo commented Sep 13, 2016

https://github.com/apollostack/apollo-client/blob/a92631da86b2ae493625973447a02b1204a3059f/src/networkInterface.ts#L35
So probably I need a way to convert type Document to a simple string...

interface Request {
  debugName?: string;
  query?: Document;  // this mismatch with graphql( ) from graphql package
  variables?: Object;
  operationName?: string;
  [additionalKey: string]: any;
}

@linonetwo
Copy link
Author

linonetwo commented Sep 13, 2016

Well, I use printAST( ) like:

const REST2GraphQLInterface = {
  query(GraphQLRequest) {
    return graphql(
      executableSchema, // schema: GraphQLSchema
      printAST(GraphQLRequest.query), // requestString: string
      undefined, // rootValue?: ?any
      { // contextValue?: ?any,
        Config: new Config({ connector: serverConnector }),
        User: new User({ connector: serverConnector }),
        PowerEntity: new PowerEntity({ connector: serverConnector }),
        FortuneCookie: new FortuneCookie(),
      },
      GraphQLRequest.variables, // variableValues?: ?{[key: string]: any}
      undefined // operationName?: ?string
    );
  }
};

It works!
Big thanks to you for all those awesome work!

@jurajkrivda
Copy link

jurajkrivda commented Dec 1, 2016

import { print } from 'graphql/language/printer';
print(request.query)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants