tendant / graphql-clj

A Clojure library that provides GraphQL implementation.
Eclipse Public License 1.0
285 stars 22 forks source link

Cannot query field '__typename' #52

Closed carld closed 7 years ago

carld commented 7 years ago

The GraphQL spec (https://github.com/facebook/graphql/blob/af50a0a7e4fec972a6b7e1f8aaa518e41b459116/README.md) mentions that the special field __typename is defined on every object, and it appears this is not supported in graphql-clj 0.1.20.

I would never have noticed except the Apollo client automatically adds the __typename field to queries, and my graphql-clj based app is returning:

{"errors":[{"error":"Cannot query field '__typename' on type 'Account'.","loc":{"line":1,"column":37}}]}

I'm a clojure noob so any suggestions much appreciated

Thanks

carld commented 7 years ago

I've found the TODO in fields_on_correct_type.clj ...

https://github.com/tendant/graphql-clj/blob/104dc433699310443d6835a3f97f971bb34c3f99/src/graphql_clj/validator/rules/fields_on_correct_type.clj#L12

carld commented 7 years ago

Just for any passer by, to prevent Apollo from adding __typename to queries, it can be disabled with an option passed to the ApolloClient constructor

 const networkInterface = createNetworkInterface({ uri: 'http://localhost:3002/graphql' });
+const addTypename = false;

 const client = new ApolloClient({
-  networkInterface,
+    networkInterface,
+    addTypename
 });

I'll leave the issue open for now in case anyone wants to add thoughts on how to implement __typename in graphql-clj.

tendant commented 7 years ago

Thanks @carld for reporting this issue. We are working on the next version of graphql-clj, which you can find it from here https://github.com/tendant/graphql-clj/tree/new-ast. We plan to support this in the new version.

carld commented 7 years ago

@tendant Awesome thanks, great work! 👍