haskell-graphql / graphql-api

Write type-safe GraphQL services in Haskell
BSD 3-Clause "New" or "Revised" License
406 stars 35 forks source link

Request for help with ' No instance for (GraphQL.Resolver.HasResolver ' build error #181

Closed Happy0 closed 6 years ago

Happy0 commented 6 years ago

Sorry if this is the wrong place to ask for help. Please let me know if there's an alternative...

I started a toy project tonight to try and learn about graphQL / some more haskell (and possibly haxl for concurrently handling the graphql query): https://github.com/Happy0/lichess-graphql-api

When I try to build it I'm getting the following error:

Building executable 'lichess-graphql-api-exe' for lichess-graphql-api-0.1.0.0..
[2 of 2] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/lichess-graphql-api-exe/lichess-graphql-api-exe-tmp/Main.o )

/home/happy0/projects/lichess-graphql-api/app/Main.hs:12:18: error:
    • No instance for (GraphQL.Resolver.HasResolver
                         IO [Lichess.GraphQL.Model.Game.GameConnection])
        arising from a use of ‘interpretAnonymousQuery’
    • In a stmt of a 'do' block:
        testResult <- interpretAnonymousQuery
                        @Query queryHandler "query { user (id: happy0) { id } }"
      In the expression:
        do testResult <- interpretAnonymousQuery
                           @Query queryHandler "query { user (id: happy0) { id } }"
           putStrLn $ show $ encode testResult
      In an equation for ‘main’:
          main
            = do testResult <- interpretAnonymousQuery
                                 @Query queryHandler "query { user (id: happy0) { id } }"
                 putStrLn $ show $ encode testResult
   |
12 |    testResult <- interpretAnonymousQuery @Query queryHandler "query { user (id: happy0) { id } }"
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

--  While building custom Setup.hs for package lichess-graphql-api-0.1.0.0 using:
      /home/happy0/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.0.1.0 build lib:lichess-graphql-api exe:lichess-graphql-api-exe --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

I'm not sure how to resolve this error.

Here's some context about where the error might be coming from:

Any suggestions about what I might be doing wrong?

Thanks Gordon

jml commented 6 years ago

Hi @Happy0,

I don't have time to look into this right now—maybe some day though. Perhaps someone else might be able to answer your question.

You also might want to try asking the question with a haskell-graphql tag on StackOverflow.

Kind regards, jml

Happy0 commented 6 years ago

I've got past that particular problem - on to the next!

For anyone else running into a similar error (trying to avoid this situation here: https://xkcd.com/979/) :

I got past that particular problem by changing my types from [ Type ] to List Type, and Int to Int32 in my field definitions in this commit here:

https://github.com/Happy0/lichess-graphql-api/commit/ba5b0e75ed1f7132015b159724295cffd6442172

This is because the types you're using have to implement the 'HasResolver' typeclass. The 'Int32' and 'List' types are examples of types that already implement this typeclass:

https://github.com/haskell-graphql/graphql-api/blob/883575019cb7b8d0d282af4d30a8dd9a68ca362e/src/GraphQL/Internal/Resolver.hs#L155

jml commented 6 years ago

Thanks for replying, and for sharing your solution!