Giter Site home page Giter Site logo

apollo-scalajs's Introduction

Archival

This repo was archived by the Apollo Security team on 2023-05-26

Apollo Scala.js

use Apollo Client and React Apollo from your Scala.js apps!

View the docs

Installation

Add the dependency to your build.sbt

resolvers += "Apollo Bintray" at "https://dl.bintray.com/apollographql/maven/"
libraryDependencies += "com.apollographql" %%% "apollo-scalajs-core" % "0.8.0" // if you are writing a vanilla Scala.js app
libraryDependencies += "com.apollographql" %%% "apollo-scalajs-react" % "0.8.0" // if you are writing a React Scala.js app

You probably also want to add other Slinky modules such as the web module, so check out the instructions at https://slinky.dev

To set up the code generator, which uses the Apollo CLI to generate static types for your GraphQL queries, first install apollo npm i -g apollo

and then set up SBT to automatically run it

val namespace = "your package here"

(sourceGenerators in Compile) += Def.task {
  import scala.sys.process._

  val out = (sourceManaged in Compile).value

  out.mkdirs()

  Seq(
    "apollo", "client:codegen", s"--queries=${((sourceDirectory in Compile).value / "graphql").getAbsolutePath}/*.graphql",
    s"--localSchemaFile=${(baseDirectory.value / "schema.json").getAbsolutePath}",
    "--target=scala",
    s"--namespace=$namespace",
    graphQLScala.getAbsolutePath
  ).!

  Seq(out / "graphql.scala")
}

Usage

Once you have placed some GraphQL queries in src/main/graphql, you can use the generated types to create GraphQL-powered React components!

To integrate GraphQL data in your React tree, simply use the Query component to render subtrees based on a specified query.

Query(UsdRatesQuery)  { queryStatus =>
  if (queryStatus.loading) "Loading..."
  else if (queryStatus.error) s"Error! ${queryStatus.error.message}"
  else {
    div(queryStatus.data.get.rates.mkString(", "))
  }
}

For more on implementing advanced components, follow the instructions at https://slinky.shadaj.me

Next, to initialize Apollo Client in your application, first create an instance of the client (here using Apollo Boost)

val client = ApolloBoostClient(
  uri = "https://graphql-currency-rates.glitch.me"
)

Finally, wrap your React component tree inside an ApolloProvider component, which all components inside to perform GraphQL queries with the specified client

ApolloProvider(client)(
  ...
)

apollo-scalajs's People

Contributors

espinhogr avatar matthewpflueger avatar mclaudt avatar notmu avatar peakematt avatar ramnivas avatar shadaj avatar trevorblades avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apollo-scalajs's Issues

Enhance ApolloBoostClient with credentials or at least ApolloClient as a workaround

Hi, I think this is both a small enhancement proposal for apollo-scalajs facades and perhaps an issue outside the scope of this project related to the underlying fetching API that's sending the requests

Proposed Enhancement
In addition to providing a uri for the ApolloBoostClient, the API should allow a cookie specification for authentication. In my case, I am trying to specify the omit option to stop large cookies from getting sent, which appears to be a documented option if fetch is the underlying request handler?.

Here is an example that should work presuming "fetch" is the underlying request handler but unfortunately cookies are still showing up in the request headers despite attempts applying options:

val client = new ApolloBoostClient(
    ApolloBoostClientOptions(
      uri = s"http://${host}",
      // I don't think "opts" is documented, but just to cover my bases I included it as SO post solutions did...
      fetchOptions = js.Dynamic.literal("credentials" -> "omit", "opts" -> js.Dynamic.literal("credentials" -> "omit"))
    )
  )

Potential Related Issue
In case this is due to a closed issue that still seems to be in effect, as suggested I implemented adding credentials attribute that was missing:

case class HttpLinkOptions(uri: String, credentials: String)

@JSImport("apollo-link-http", "HttpLink")
@js.native
class HttpLink(options: ObjectOrWritten[HttpLinkOptions]) extends ApolloLink

and the following WORKS!:


val client = new ApolloClient(
    ApolloClientOptions(
      link = new HttpLink(
        HttpLinkOptions(
          uri = someHost,
          credentials = "omit"
        )
      ),
      cache = InMemoryCache,
      ssrMode = false
    )
  )

All of my requests are successful, so I know I'm sending them correctly, it's just the cookies I want gone. Is there a hope of getting credentials working with the higher level apollo-scalajs Boost client and render Query/Mutation components?

I haven't tested cors yet, but I presume that included is another credentials option others would benefit from in addition to omit and same-origin.

Also, and this is just me nit-picking, why are apollo-scalajs graphql requests all getting sent as a POST? For basic queries, I always send them as a GET (just to follow REST). Interested to hear why POST is preferred...

Cannot compile example

I'm trying to run the example like this:

sbt example/fastOptJS::startWebpackDevServer

And then I get the following error:

[info] Loading settings for project global-plugins from plugins.sbt ...
[info] Loading global plugins from /home/felix/.sbt/1.0/plugins
[info] Loading settings for project apollo-scalajs-build from plugins.sbt ...
[info] Loading project definition from /tmp/tmp.4XopoXrhQQ/apollo-scalajs/project
[info] Loading settings for project apollo-scalajs from build.sbt ...
[info] Loading settings for project example from build.sbt ...
[info] Loading settings for project tests from build.sbt ...
[info] Loading settings for project react from build.sbt ...
[info] Loading settings for project core from build.sbt ...
[info] Set current project to apollo-scalajs (in build file:/tmp/tmp.4XopoXrhQQ/apollo-scalajs/)
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
Loading Apollo Project [started]
Loading Apollo Project [completed]
Generating query files [started]
Generating query files with 'scala' target [title changed]
Generating query files with 'scala' target [failed]
→ Cannot use GraphQLObjectType "Query" from another module or realm.

Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.

https://yarnpkg.com/en/docs/selective-version-resolutions

Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
    Error: Cannot use GraphQLObjectType "Query" from another module or realm.

    Ensure that there is only one instance of "graphql" in the node_modules
    directory. If different versions of "graphql" are the dependencies of 
    other
    relied on modules, use "resolutions" to ensure only one version is 
    installed.

    https://yarnpkg.com/en/docs/selective-version-resolutions
  | => example / Compile / managedSources 3s
    Duplicate "graphql" modules cannot be used at the same time since 
    different
    versions may have different capabilities and behavior. The data from one
    version used in the function from another could produce confusing and
    spurious results.
[info] Compiling 4 Scala sources to /tmp/tmp.4XopoXrhQQ/apollo-scalajs/example/target/scala-2.12/classes ...
[error] [E-1] IO error while decoding /tmp/tmp.4XopoXrhQQ/apollo-scalajs/example/target/scala-2.12/src_managed/main/graphql.scala with UTF-8: /tmp/tmp.4XopoXrhQQ/apollo-scalajs/example/target/scala-2.12/src_managed/main/graphql.scala (No such file or directory)
[error]       Please try specifying another one using the -encoding option
[info] Legend: Ln = line n, Cn = column n, En = error n
[info] Updating NPM dependencies
[info] added 19 packages, removed 45 packages, changed 21 packages, and audited 1119 packages in 11s
[info] 59 packages are looking for funding
[info]   run `npm fund` for details
[info] 10 vulnerabilities (4 low, 3 moderate, 3 high)
[info] To address issues that do not require attention, run:
[info]   npm audit fix
[info] To address all issues, run:
[info]   npm audit fix --force
[info] Run `npm audit` for details.
[error] (example / Compile / compileIncremental) Compilation failed
[error] Total time: 17 s, completed Apr 2, 2021 6:50:00 PM

What I already tried:

  • useYarn := true
  • check node_modules folders (project and global) and lock-files for other graphql dependencies
  • upgrading apollo dependencies apollo and @apollo/client
  • npmResolutions in Compile := Map("graphql" -> "14.7.0") in build.sbt

all versions look fine (with npmResultions):

/tmp/tmp.4XopoXrhQQ/apollo-scalajs/example/target/scala-2.12/scalajs-bundler/main on  master [!?] 
❯ npm ls graphql
main@ /tmp/tmp.4XopoXrhQQ/apollo-scalajs/example/target/scala-2.12/scalajs-bundler/main
├─┬ @apollo/[email protected]
│ ├─┬ @graphql-typed-document-node/[email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ └── [email protected]
└─┬ [email protected]
  ├─┬ [email protected]
  │ └── [email protected] deduped
  ├─┬ [email protected]
  │ ├─┬ @apollo/[email protected]
  │ │ └── [email protected] deduped
  │ ├─┬ @apollographql/[email protected]
  │ │ ├─┬ @apollographql/[email protected]
  │ │ │ └── [email protected] deduped
  │ │ ├─┬ @apollographql/[email protected]
  │ │ │ └── [email protected] deduped
  │ │ ├─┬ @apollographql/[email protected]
  │ │ │ └── [email protected] deduped
  │ │ └── [email protected] deduped
  │ ├─┬ [email protected]
  │ │ └─┬ [email protected]
  │ │   └── [email protected] deduped
  │ ├─┬ [email protected]
  │ │ └── [email protected] deduped
  │ ├─┬ [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ └── [email protected] deduped
  │ │ └── [email protected] deduped
  │ ├─┬ [email protected]
  │ │ └── [email protected] deduped
  │ └── [email protected] deduped
  ├─┬ [email protected]
  │ └── [email protected] deduped
  └── [email protected] deduped

Seems to be related to: graphql/graphql-js#491

Update to use slinky 0.2.0

Would really like to use this with the latest slinky release! Happy to provide a PR if you'd give a couple of pointers on what needs to be done...

Update to Slinky 0.5.0

This is a little bit premature but it looks like Slinky 0.5.0 will be out soon (https://gitter.im/shadaj/slinky?at=5b9d362afcba1254fabe13a2).

I just tried using it but I get a bunch of errors:

[error] Referring to non-existent method slinky.readwrite.Writer$.combine(magnolia.CaseClass)slinky.readwrite.Writer
[error]   called from com.apollographql.scalajs.react.ApolloProvider$.propsTypeclass$macro$1$1()slinky.readwrite.Writer
[error]   called from com.apollographql.scalajs.react.ApolloProvider$.<init>()
[error]   called from ReactGraphQLApp.renderApp(slinky.core.facade.ReactElement,java.lang.String)slinky.core.facade.ReactInstance
[error]   called from StarWarsApp$.renderApp(slinky.core.facade.ReactElement,java.lang.String)slinky.core.facade.ReactInstance
[error]   called from StarWarsApp$.main([java.lang.String)scala.Unit
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   com.apollographql.scalajs.react.ApolloProvider$
[error]   StarWarsApp$
[error] Referring to non-existent method slinky.readwrite.Writer$.combine(magnolia.CaseClass)slinky.readwrite.Writer
[error]   called from com.apollographql.scalajs.ApolloBoostClient$.apolloboostclientoptionsTypeclass$macro$9$1()slinky.readwrite.Writer
[error]   called from com.apollographql.scalajs.ApolloBoostClient$.apply(java.lang.String)com.apollographql.scalajs.ApolloBoostClient
[error]   called from ReactGraphQLApp.renderApp(slinky.core.facade.ReactElement,java.lang.String)slinky.core.facade.ReactInstance
[error]   called from StarWarsApp$.renderApp(slinky.core.facade.ReactElement,java.lang.String)slinky.core.facade.ReactInstance
[error]   called from StarWarsApp$.main([java.lang.String)scala.Unit
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   com.apollographql.scalajs.ApolloBoostClient$
[error]   StarWarsApp$

I might have a go and see if I can get it to work.

imported `react' is permanently hidden by definition of package react in package scalajs

Hello, thanks for your work and for a great software!

I have found impossible to follow readme for example project:

$ git clone https://github.com/apollographql/react-apollo-scalajs.git
$ cd react-apollo-scalajs
$ sbt example/fastOptJS::startWebpackDevServer

gives

[info] Loading global plugins from /home/user/.sbt/1.0/plugins
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from /home/user/react-apollo-scalajs/project
[info] Updating ProjectRef(uri("file:/home/user/react-apollo-scalajs/project/"),
"react-apollo-scalajs-build")...
[info] Done updating.
[warn] Found version conflict(s) in library dependencies; some are suspected to 
be binary incompatible:
[warn] 	* org.scala-js:sbt-scalajs:0.6.21 is selected over 0.6.19
[warn] 	    +- default:react-apollo-scalajs-build:0.1.0-SNAPSHOT (scalaVersion=2
.12, sbtVersion=1.0) (depends on 0.6.19)
[warn] 	    +- ch.epfl.scala:sbt-scalajs-bundler:0.9.0 (scalaVersion=2.12, sbtVe
rsion=1.0) (depends on 0.6.19)
[warn] Run 'evicted' to see detailed eviction warnings
[info] Loading settings from build.sbt ...
[info] Loading settings from build.sbt ...
/home/user/react-apollo-scalajs/tests/build.sbt:18: warning: value RuntimeDOM in
trait DependencyBuilders is deprecated (since 0.6.20): Requesting a DOM-enabled
JS env with `jsDependencies += RuntimeDOM` or `requiresDOM := true` will not be
supported in Scala.js 1.x. Instead, explicitly select a suitable JS with `jsEnv
`, e.g., `jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv`.
jsDependencies += RuntimeDOM % Test
                 ^
[info] Loading settings from build.sbt ...
[info] Loading settings from build.sbt ...
[info] Loading settings from build.sbt ...
[info] Set current project to apollo-scalajs (in build file:/home/user/react-apo
llo-scalajs/)
[info] Updating core...
[info] Done updating.
[info] Updating react...
[info] Done updating.
[info] Updating example...
[info] Done updating.
[info] Compiling 11 Scala sources to /home/user/react-apollo-scalajs/core/target
/scala-2.12/classes ...
[info] /home/user/react-apollo-scalajs/core/src/main/scala/com/apollographql/sca
lajs/link/Observable.scala:26:73: magnolia: could not find any direct subtypes o
f trait UndefOr
[info]                 error: ObjectOrWritten[js.UndefOr[js.Any => Unit]] = js.u
ndefined,
[info]                                                                         ^
[info] Done compiling.
[info] Compiling 4 Scala sources to /home/user/react-apollo-scalajs/react/target
/scala-2.12/classes ...
[info] Done compiling.
[info] Compiling 5 Scala sources to /home/user/react-apollo-scalajs/example/targ
et/scala-2.12/classes ...
[error] /home/user/react-apollo-scalajs/example/src/main/scala/com/apollographql
/scalajs/AuthorView.scala:3:34: object react is not a member of package com.apol
lographql.scalajs.com.apollographql.scalajs
[error] import com.apollographql.scalajs.react.Query
[error]                                  ^
[warn] /home/user/react-apollo-scalajs/example/src/main/scala/com/apollographql/
scalajs/AuthorView.scala:5:32: imported `react' is permanently hidden by definit
ion of package react in package scalajs
[warn] import slinky.core.annotations.react
[warn]                                ^
[error] <macro>:8:34: not found: value Query
[error]     def render(): ReactElement = Query(AuthorQuery, AuthorQuery.Variable
s(props.id))(_.data.map(d => div(d.author.toString)).getOrElse(h1("loading!")))
[error]                                  ^
[error] <macro>:8:40: not found: value AuthorQuery
[error]     def render(): ReactElement = Query(AuthorQuery, AuthorQuery.Variable
s(props.id))(_.data.map(d => div(d.author.toString)).getOrElse(h1("loading!")))
[error]                                        ^
[error] <macro>:8:53: not found: value AuthorQuery
[error]     def render(): ReactElement = Query(AuthorQuery, AuthorQuery.Variable
s(props.id))(_.data.map(d => div(d.author.toString)).getOrElse(h1("loading!")))
[error]                                                     ^
[error] /home/user/react-apollo-scalajs/example/src/main/scala/com/apollographql
/scalajs/Main.scala:3:34: object react is not a member of package com.apollograp
hql.scalajs.com.apollographql.scalajs
[error] import com.apollographql.scalajs.react.ApolloProvider
[error]                                  ^
[error] /home/user/react-apollo-scalajs/example/src/main/scala/com/apollographql
/scalajs/Main.scala:30:7: not found: value ApolloProvider
[error]       ApolloProvider(client)(
[error]       ^
[error] /home/user/react-apollo-scalajs/example/src/main/scala/com/apollographql
/scalajs/PostsView.scala:3:34: object react is not a member of package com.apoll
ographql.scalajs.com.apollographql.scalajs
[error] import com.apollographql.scalajs.react.Query
[error]                                  ^
[warn] /home/user/react-apollo-scalajs/example/src/main/scala/com/apollographql/
scalajs/PostsView.scala:5:32: imported `react' is permanently hidden by definiti
on of package react in package scalajs
[warn] import slinky.core.annotations.react
[warn]                                ^
[error] <macro>:8:34: not found: value Query
[error]     def render(): ReactElement = Query(AllPostsQuery)(res => res.data.ma
p(d => div(d.posts.toList.flatten.flatten.map(post => div(key := post.id.toStrin
g)(h1(post.title.getOrElse[String]("???")), h2(post.votes.getOrElse(0).toString)
, UpVote(post.id))))).getOrElse(h1("loading!")))
[error]                                  ^
[error] <macro>:8:40: not found: value AllPostsQuery
[error]     def render(): ReactElement = Query(AllPostsQuery)(res => res.data.ma
p(d => div(d.posts.toList.flatten.flatten.map(post => div(key := post.id.toStrin
g)(h1(post.title.getOrElse[String]("???")), h2(post.votes.getOrElse(0).toString)
, UpVote(post.id))))).getOrElse(h1("loading!")))
[error]                                        ^
[error] /home/user/react-apollo-scalajs/example/src/main/scala/com/apollographql
/scalajs/UpVote.scala:3:34: object react is not a member of package com.apollogr
aphql.scalajs.com.apollographql.scalajs
[error] import com.apollographql.scalajs.react.Mutation
[error]                                  ^
[warn] /home/user/react-apollo-scalajs/example/src/main/scala/com/apollographql/
scalajs/UpVote.scala:5:32: imported `react' is permanently hidden by definition 
of package react in package scalajs
[warn] import slinky.core.annotations.react
[warn]                                ^
[error] <macro>:8:34: not found: value Mutation
[error]     def render(): ReactElement = Mutation(UpVoteMutation)((mut, res) => 
button(onClick := (() => mut(UpVoteMutation.Variables(props.postId))), disabled 
:= res.loading)(div(if (res.loading) "upvoting" else "upvote!")))
[error]                                  ^
[error] <macro>:8:43: not found: value UpVoteMutation
[error]     def render(): ReactElement = Mutation(UpVoteMutation)((mut, res) => 
button(onClick := (() => mut(UpVoteMutation.Variables(props.postId))), disabled 
:= res.loading)(div(if (res.loading) "upvoting" else "upvote!")))
[error]                                           ^
[error] /home/user/react-apollo-scalajs/example/target/scala-2.12/src_managed/ma
in/graphql.scala:7:54: type GraphQLQuery is not a member of package com.apollogr
aphql.scalajs.com.apollographql.scalajs
[error] object AuthorQuery extends com.apollographql.scalajs.GraphQLQuery {
[error]                                                      ^
[error] /home/user/react-apollo-scalajs/example/target/scala-2.12/src_managed/ma
in/graphql.scala:15:45: object gql is not a member of package com.apollographql.
scalajs.com.apollographql.scalajs
[error]   val operation = com.apollographql.scalajs.gql(operationString)
[error]                                             ^
[error] /home/user/react-apollo-scalajs/example/target/scala-2.12/src_managed/ma
in/graphql.scala:36:56: type GraphQLQuery is not a member of package com.apollog
raphql.scalajs.com.apollographql.scalajs
[error] object AllPostsQuery extends com.apollographql.scalajs.GraphQLQuery {
[error]                                                        ^
[error] /home/user/react-apollo-scalajs/example/target/scala-2.12/src_managed/ma
in/graphql.scala:45:45: object gql is not a member of package com.apollographql.
scalajs.com.apollographql.scalajs
[error]   val operation = com.apollographql.scalajs.gql(operationString)
[error]                                             ^
[error] /home/user/react-apollo-scalajs/example/target/scala-2.12/src_managed/ma
in/graphql.scala:64:57: type GraphQLMutation is not a member of package com.apol
lographql.scalajs.com.apollographql.scalajs
[error] object UpVoteMutation extends com.apollographql.scalajs.GraphQLMutation 
{
[error]                                                         ^
[error] /home/user/react-apollo-scalajs/example/target/scala-2.12/src_managed/ma
in/graphql.scala:73:45: object gql is not a member of package com.apollographql.
scalajs.com.apollographql.scalajs
[error]   val operation = com.apollographql.scalajs.gql(operationString)
[error]                                             ^
[warn] three warnings found
[error] 18 errors found
[error] (example / Compile / compileIncremental) Compilation failed
[error] Total time: 23 s, completed Jul 20, 2018 7:36:29 PM
$

I have tried to separate project "example" and rename it's internal package "com.apollographql.scalajs" to "foobar" to exclude possible collisions, but it was not a success.

If confirmed, it could deeply disappoint newcomers, but considering that some time ago all was working and it's somehow connected with new versions, solution should be simple.

Thanks in advance.

Release 0.4

Can we please get 0.4 released to bintray? Thanks.

Where can I find ApolloBoostClient?

I'm trying to get started and have trouble to compile the example:

import com.apollographql.scalajs._
val client = ApolloBoostClient(
  uri = "http://localhost:8080/v1/graphql"
)

But it doesn't find ApolloBoostClient. Any hints?

Code generation in example (from this repo) not successfully generating .scala file

Hi, I downloaded this repo and after installing apollo tried running the example but got the below error that looks to be source code generation failing.

Perhaps is this due to a bug in a newer version of apollo than you might be using? What version of apollo do you test against?

I'm using:

apollo --version
apollo/2.1.9 linux-x64 node-v10.14.2

npm --version
6.4.1

Here's the error I get:

me@machine:/home/me/apollo-scalajs-master$ sbt example/fastOptJS::startWebpackDevServer
[info] Loading settings from idea.sbt,sbt-updates.sbt ...
[info] Loading global plugins from /nfs/u/me/.sbt/1.0/plugins
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from /home/me/apollo-scalajs-master/project
[info] Updating ProjectRef(uri("file:/home/me/apollo-scalajs-master/project/"), "apollo-scalajs-master-build")...
[info] Done updating.
[warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[warn]  * org.scala-js:sbt-scalajs:0.6.24 is selected over 0.6.22
[warn]      +- ch.epfl.scala:sbt-scalajs-bundler:0.13.1 (scalaVersion=2.12, sbtVersion=1.0) (depends on 0.6.22)
[warn]      +- default:apollo-scalajs-master-build:0.1.0-SNAPSHOT (scalaVersion=2.12, sbtVersion=1.0) (depends on 0.6.22)
[warn] Run 'evicted' to see detailed eviction warnings
[info] Loading settings from build.sbt ...
[info] Loading settings from build.sbt ...
/home/me/apollo-scalajs-master/tests/build.sbt:18: warning: value RuntimeDOM in trait DependencyBuilders is deprecated (since 0.6.20): Requesting a DOM-enabled JS env with `jsDependencies += RuntimeDOM` or `requiresDOM := true` will not be supported in Scala.js 1.x. Instead, explicitly select a suitable JS with `jsEnv`, e.g., `jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv`.
jsDependencies += RuntimeDOM % Test
                  ^
[info] Loading settings from build.sbt ...
[info] Loading settings from build.sbt ...
[info] Loading settings from build.sbt ...
[info] Set current project to apollo-scalajs (in build file:/home/me/apollo-scalajs-master/)
[info] Updating core...
[info] Done updating.
[info] Updating react...
[info] Done updating.
[info] Updating example...
[info] Done updating.
[info] Compiling 11 Scala sources to /home/me/apollo-scalajs-master/core/target/scala-2.12/classes ...
 ›   Error: Unexpected argument: 
 ›   /home/me/apollo-scalajs-master/example/t
 ›   arget/scala-2.12/src_managed/main/graphql.scala
 ›   See more help with --help
[info] Done compiling.
[info] Compiling 4 Scala sources to /home/me/apollo-scalajs-master/react/target/scala-2.12/classes ...
[info] /home/me/apollo-scalajs-master/react/src/main/scala/com/apollographql/scalajs/react/Mutation.scala:21:26: Using fallback derivation for type Error (derivation: MacroReadersImpl)
[info]       Reader.optionReader[Error].read(dyn.error.asInstanceOf[js.Object]),
[info]                          ^
[info] /home/me/apollo-scalajs-master/react/src/main/scala/com/apollographql/scalajs/react/Query.scala:16:36: Using fallback derivation for type Error (derivation: MacroReadersImpl)
[info]     val error = Reader.optionReader[Error].read(dyn.error.asInstanceOf[js.Object])
[info]                                    ^
[info] Done compiling.
[info] Compiling 5 Scala sources to /home/me/apollo-scalajs-master/example/target/scala-2.12/classes ...
[error] source file '/home/me/apollo-scalajs-master/example/target/scala-2.12/src_managed/main/graphql.scala' could not be found
[error] one error found
[error] (example / Compile / compileIncremental) Compilation failed
[error] Total time: 20 s, completed Jan 9, 2019 5:55:13 PM

Support pre-processing of GraphQL queries

Thank you for this awesome integration with scala.js … im currently experimenting with a basic template that produces acceptable bundle sizes and figured that this integration is missing a great opportunity to save bytes by pre-processing the graphql queries during build time and removing the runtime dependency on graphql-tag!

For a reference you can checkout https://github.com/gajus/babel-plugin-graphql-tag which does not work with this library atm … i can only guess because it only removes imports / gql template tags which are not used by this library.

Support Querying in componentDidMount instead of render

Hi and thanks again for the suite of react tools! Currently Query must return a ReactElement as part of a render. But what about graphql queries that need to run only to initialize state? Those should run in componentDidMount and not render.

For instance, running this can't work because state can't be set inside render wtihout triggering warnings/errors in react:

def render(): ReactElement = {
    Query(someQuery) {
      _.data.map { d =>
        setState(dataLoaded = true)
      
      div("state saved!")
    }.getOrElse(h1("loading!"))
    }
  }

results in:

Warning: Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state.

When I try using Query inside componentDidMount it appears to never make any requests.

Support custom decoder?

If I define a custom JSON decoder, is it possible to pass this to query in such a way that it creates the scala objects using that decoder?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.