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

Cannot have Array Int as a Var? #112

Open
CGenie opened this issue Jan 17, 2023 · 4 comments
Open

Cannot have Array Int as a Var? #112

CGenie opened this issue Jan 17, 2023 · 4 comments

Comments

@CGenie
Copy link

CGenie commented Jan 17, 2023

Hello,

I'm trying to create a GraphQL query template with variables. I have code like this:

type ContextsForNgramsQuery
  = { my_query :: Args
      { my_ids :: Var "my_ids" (Array Int) }
      {...} }

and I use it like this later:

{ my_query: Var :: _ "my_ids" (Array Int) } ==> ...

However, I'm getting this error:

  No type class instance was found for
                                          
    GraphQL.Client.Args.ArgGql Int        
                               (Array Int)
                                          

while solving type class constraint
                                                                         
  GraphQL.Client.Args.ArgGql Int                                         
                             (Var @Symbol @Type "ngrams_ids" (Array Int))

When I replace my_ids to Var "my_ids" Int, this compiles without errors.

Does this mean Array Int is not supported as ArgGql and if so, is there any reason to do this? Here

https://pursuit.purescript.org/packages/purescript-graphql-client/9.3.2/docs/GraphQL.Client.Args#t:ArgGql

I see in particular this instance:

instance argToGqlArray :: ArgGql param arg => ArgGql (Array param) (Array arg)

I guess we could add this as well?

instance ArgGql param arg => ArgGql param (Array arg)
@roryc89
Copy link
Contributor

roryc89 commented Jan 17, 2023

Does this mean Array Int is not supported as ArgGql and if so, is there any reason to do this?

It should support an Array Int Var if the schema specifies that field as an Array Int.

But it could be an issue with the newer purs version handling class instances differently.

Are you able to add a minimal, reproducible example so that I can see if this is a bug in the library or a schema/value mismatch?

I guess we could add this as well?

instance ArgGql param arg => ArgGql param (Array arg)

That would allow arrays to be used where the schema specifies a single value type so I think would cause runtime errors

@CGenie
Copy link
Author

CGenie commented Jan 18, 2023

With something like this

https://paste.sr.ht/~cgenie/48ee5986da096f80cfbdce68bc2185ec10d5fc35

I'm getting this error:

Error found:
in module TestArrayInt
at src/Gargantext/Components/GraphQL/TestArrayInt.purs:68:18 - 68:36 (line 68, column 18 - line 68, column 36)

  No type class instance was found for
                                          
    GraphQL.Client.Args.ArgGql Int        
                               (Array Int)
                                          

while solving type class constraint
                                                                     
  GraphQL.Client.Args.ArgGql Int                                     
                             (Var @Symbol @Type "my_ids" (Array Int))
                                                                     
while applying a function queryGql
  of type GqlQuery                                    
            { myquery :: ... @Type                    
                           { my_ids :: ...            
                           }                          
                           { response :: Int          
                           }                          
            }                                         
            t2                                        
            t3                                        
           => ReadForeign t3 => String -> t2 -> Aff t3
  to argument "myquery"
while checking that expression queryGql "myquery"
  has type t0 -> t1
in value declaration runMyQuery

where t0 is an unknown type
      t1 is an unknown type
      t2 is an unknown type
      t3 is an unknown type

See https://github.com/purescript/documentation/blob/master/errors/NoInstanceFound.md for more information,
or to contribute content related to this error.


[error] Failed to build.

I'm using ps 0.15.7.

@CGenie
Copy link
Author

CGenie commented Jan 24, 2023

Anyone have an idea what's going on here? :)

@CGenie
Copy link
Author

CGenie commented Jan 24, 2023

As a workaround, I added

newtype Ids = Array Int
instance EncodeJson Ids where
  encodeJson (Ids ids) = encodeJson ids
instance ArgGql Int Ids
instance VarTypeName Ids where
  varTypeName _ = "Ids!"

and replaced Array Int with Ids.

EDIT: It should be

instance VarTypeName Ids where
  varTypeName _ = "[Int!]!"

instead. Otherwise you need to introduce the Ids type on the backend.

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