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

Fails to escape object keyword on schema generation #1224

Closed
kryptt opened this issue Dec 22, 2021 · 10 comments · Fixed by #1225
Closed

Fails to escape object keyword on schema generation #1224

kryptt opened this issue Dec 22, 2021 · 10 comments · Fixed by #1225

Comments

@kryptt
Copy link

kryptt commented Dec 22, 2021

After upgrading to 1.3.1 the schem for github (https://api.github.com/graphql) is no longer correctly generated

when trying to compile Repository or TreeEntry classes you can see that the object field is not escaped correctly in the generated code:

[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/TreeEntry.scala:57:24: ident
ifier expected but 'object' found.                                                                                                                                         
[error] def objectInterface[A](object: SelectionBuilder[GitObject, A]): SelectionBuilder[TreeEntry, Option[A]] = _root_.caliban.client.SelectionBuilder.Field("object", Opt
ionOf(Obj(object)))                                                                                                                                                        
[error]                        ^                                                                                                                                           
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/TreeEntry.scala:58:1: ':' ex
pected but '}' found.                                                                                                                                                      
[error] }                                                                                                                                                                  
[error] ^                                                                                                                                                                  
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/TreeEntry.scala:57:183: proc
edure syntax is deprecated: instead, add `: Unit` to explicitly declare `objectInterface`'s return type                                                                    
[error] def objectInterface[A](object: SelectionBuilder[GitObject, A]): SelectionBuilder[TreeEntry, Option[A]] = _root_.caliban.client.SelectionBuilder.Field("object", Opt
ionOf(Obj(object)))                                                                                                                                                        
[error]                                                                                                                                                                    
                   ^                                                                                                                                                       
[error] three errors found                                     
@ghostdogpr
Copy link
Owner

Indeed, the field was not escaped in the newly added function. I fixed it in #1225. Can you confirm that it's fixed with the latest snapshot?

@kryptt
Copy link
Author

kryptt commented Dec 27, 2021

I tried with this snapshot:

addSbtPlugin("com.github.ghostdogpr" % "caliban-codegen-sbt" % "1.3.1+9-7df8ec8a-SNAPSHOT")

and it still fails:

sbt:kobo-assist-root> commands/clean
[success] Total time: 2 s, completed Dec 27, 2021, 11:16:51 AM
sbt:kobo-assist-root> commands/Compile/caliban/calibanGenerator
[success] Total time: 5 s, completed Dec 27, 2021, 11:17:15 AM
sbt:kobo-assist-root> commands/compile
[info] compiling 17 Scala sources to /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/classes ...
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/GithubGraphQLClient.scala:22431:94: identifier expected but 'object' found.
[error] def objectInterface[A](oid : Option[GitObjectID] = None, expression : Option[String] = None)(object: SelectionBuilder[GitObject, A])(implicit encoder0: ArgEncoder[Option[GitObjectID]], encoder1: ArgEncoder[Option[String]]): SelectionBuilder[Repository, Option[A]] = _root_.caliban.client.SelectionBuilder.Field("object", OptionOf(Obj(object)), arguments = List(Argument("oid", oid, "GitObjectID")(encoder0), Argument("expression", expression, "String")(encoder1)))
[error]                                                                                              ^
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/GithubGraphQLClient.scala:22440:1: ':' expected but '}' found.
[error] }
[error] ^
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/GithubGraphQLClient.scala:25980:24: identifier expected but 'object' found.
[error] def objectInterface[A](object: SelectionBuilder[GitObject, A]): SelectionBuilder[TreeEntry, Option[A]] = _root_.caliban.client.SelectionBuilder.Field("object", OptionOf(Obj(object)))
[error]                        ^
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/GithubGraphQLClient.scala:25981:1: ':' expected but '}' found.
[error] }
[error] ^
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/GithubGraphQLClient.scala:22439:168: procedure syntax is deprecated: instead, add `: Unit` to explicitly declare `objectInterface`'s return type
[error] def ownerInterface[A](owner: SelectionBuilder[RepositoryOwner, A]): SelectionBuilder[Repository, A] = _root_.caliban.client.SelectionBuilder.Field("owner", Obj(owner))
[error]                                                                                                                                                                        ^
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/GithubGraphQLClient.scala:25980:183: procedure syntax is deprecated: instead, add `: Unit` to explicitly declare `objectInterface`'s return type
[error] def objectInterface[A](object: SelectionBuilder[GitObject, A]): SelectionBuilder[TreeEntry, Option[A]] = _root_.caliban.client.SelectionBuilder.Field("object", OptionOf(Obj(object)))
[error]                                                                                                                                                                                       ^
[error] 6 errors found
[error] (commands / Compile / compileIncremental) Compilation failed

You should be able to reproduce, since it is the public github endpoint.
Here is my snippet just in case:

  .settings(
    Compile / caliban / calibanSettings += {
      calibanSetting(url("https://api.github.com/graphql"))(
        _.clientName("GithubGraphQLClient")
          .enableFmt(false)
          .packageName(githubGraphQLPackage)
          .headers(
            "Authorization" -> s"bearer ${envProperties.value.getProperty(BUILD_KEY)}"
          )
      )
    },
    coverageExcludedPackages := s"${githubGraphQLPackage}.*",
  )

@ghostdogpr
Copy link
Owner

I think it's not the latest, can you try with 1.3.1+13-93e4c000-SNAPSHOT ?

@kryptt
Copy link
Author

kryptt commented Dec 27, 2021

Ok, that fixed that problem! Thanks,

Now i'm innundated with evey place the following is used:

[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/GithubGraphQLClient.scala:4715:17743: not found: value NullFiel
d                                                                                                                                                                                                             
[error] Error occurred in an application involving default arguments.                                                                                                                                         
[error] def subjectOption[A](onAddedToProjectEvent: Option[SelectionBuilder[AddedToProjectEvent, A]] = None, onApp: Option[SelectionBuilder[App, A]] = None, onAssignedEvent: Option[SelectionBuilder[Assigned
Event, A]] = None, onAutoMergeDisabledEvent: Option[SelectionBuilder[AutoMergeDisabledEvent, A]] = None, onAutoMergeEnabledEv

If you want I can file a separate issue....

P.S. 1.2.1 works :D

@ghostdogpr
Copy link
Owner

Did you update caliban-client to the same version as the sbt plugin?

If yes, is there import caliban.client.FieldBuilder._ in the generated code? That's where NullField is.

@kryptt
Copy link
Author

kryptt commented Dec 28, 2021

You're right; I forgot to update the client as well. The import is there; but now I get this:

[info] caliban.client.FieldBuilder.ListOf[Option[Option[A]]] <: caliban.client.FieldBuilder[Option[List[Option[A]]]]?                                                                                         
[info] false                                                                                                                                                                                                  
[error] /home/rhansen/workspace/philips/swcoe-assist/commands/target/scala-2.13/src_managed/main/caliban-codegen-sbt/com/github/client/graphql/GithubGraphQLClient.scala:19054:4650: type mismatch;           
[error]   caliban.client.FieldBuilder.ListOf[scala.Option[scala.Option[A]]]|caliban.client.FieldBuilder[scala.Option[List[scala.Option[A]]]]                                                                  
[error] Error occurred in an application involving default arguments.              

@ghostdogpr
Copy link
Owner

ghostdogpr commented Dec 28, 2021

Sad! Can you post the generated code making the error (just the problematic function) and possibly the related part of the schema?

@ghostdogpr
Copy link
Owner

@kryptt found the bug and fixed it: #1237

@ghostdogpr
Copy link
Owner

Available in snapshot 1.3.1+21-44a3d7e2-SNAPSHOT

@kryptt
Copy link
Author

kryptt commented Jan 11, 2022

It did work! Thanks!

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

Successfully merging a pull request may close this issue.

2 participants