Skip to content

Commit

Permalink
apollo client3 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aappddeevv committed Oct 5, 2020
1 parent 9b603d0 commit ea2ae16
Show file tree
Hide file tree
Showing 116 changed files with 3,732 additions and 881 deletions.
7 changes: 7 additions & 0 deletions build.sbt
Expand Up @@ -409,6 +409,13 @@ lazy val apollo = project
.settings(std_settings("apollo", "Combination of apollo-boost, graphql, react-apollo"))
.settings(buildinfo_settings("apollo"))

lazy val apollo3 = project
.in(file("components/apollo3"))
.enablePlugins(ScalaJSPlugin, BuildInfoPlugin)
.dependsOn(react, vdom)
.settings(std_settings("apollo3", "Combination of apollo-boost, graphql, react-apollo"))
.settings(buildinfo_settings("apollo3"))

lazy val fabric = project
.in(file("components/fabric"))
.enablePlugins(ScalaJSPlugin, BuildInfoPlugin)
Expand Down
10 changes: 10 additions & 0 deletions components/apollo3/README.md
@@ -1 +1,11 @@
apollo client 3

Most of the types and values are moved upward to the topmost module
to improve ergonomics.

Note that react apollo client hooks return `js.UndefOr[T]` while the
standard query functions return `js.UndefOr[T|Null]`.

I'm also trying out some new facade scala file naming schemes
to see if they help with cracking down types and values more
easily.
88 changes: 48 additions & 40 deletions components/apollo3/src/main/scala/ApolloClient.scala
Expand Up @@ -27,63 +27,71 @@ import js.annotation._
import js.|
import graphql._

import client3.link._
import client3.core._
import client3.cache._
import rxjs._

trait DefaultOptions extends js.Object {
var watchQuery: js.UndefOr[WatchQueryOptions[_]] = js.undefined
var query: js.UndefOr[QueryOptions[_]] = js.undefined
var mutate: js.UndefOr[MutationOptions[_, _]] = js.undefined
var query: js.UndefOr[QueryOptions[_]] = js.undefined
var mutate: js.UndefOr[MutationOptions[_, _]] = js.undefined
}

trait ApolloClientOptions[Shape] extends js.Object {
var uri: js.UndefOr[String|UriFunction] = js.undefined
var uri: js.UndefOr[String | UriFunction] = js.undefined
var credentials: js.UndefOr[String] = js.undefined
var headers: js.UndefOr[js.Object|js.Dictionary[String]] = js.undefined
var headers: js.UndefOr[js.Object | js.Dictionary[String]] = js.undefined
var link: js.UndefOr[ApolloLink] = js.undefined
val cache: ApolloCache[Shape]
var ssrForceFetchDelay: js.UndefOr[Int] = js.undefined
var ssrMode: js.UndefOr[Boolean] = js.undefined
var connectToDevTools: js.UndefOr[Boolean] = js.undefined
var queryDeduplication: js.UndefOr[Boolean] = js.undefined
var defaultOptions: js.UndefOr[DefaultOptions] = js.undefined
var ssrForceFetchDelay: js.UndefOr[Int] = js.undefined
var ssrMode: js.UndefOr[Boolean] = js.undefined
var connectToDevTools: js.UndefOr[Boolean] = js.undefined
var queryDeduplication: js.UndefOr[Boolean] = js.undefined
var defaultOptions: js.UndefOr[DefaultOptions] = js.undefined
var assumeImmutableResults: js.UndefOr[Boolean] = js.undefined
var resolvers: js.UndefOr[Resolvers|js.Array[Resolvers]] = js.undefined
var resolvers: js.UndefOr[Resolvers | js.Array[Resolvers]] = js.undefined
var typeDefs: js.UndefOr[String | js.Array[String] | DocumentNode | js.Array[DocumentNode]] = js.undefined
var name: js.UndefOr[String] = js.undefined
var version: js.UndefOr[String] = js.undefined
var name: js.UndefOr[String] = js.undefined
var version: js.UndefOr[String] = js.undefined
}

@js.native
@JSImport("@apollo/client", "ApolloClient")
class ApolloClient[Shape](options: ApolloClientOptions[Shape]) extends DataProxy {

val link: ApolloLink = js.native
val cache: ApolloCache[CacheShape] = js.native
val disableNetworkFetches: Boolean = js.native
val version: String = js.native
val queryDeduplication: Boolean = js.native
val defaultOptions: DefaultOptions = js.native
//val typeDefs: ApolloClientOptions<TCacheShape>['typeDefs'];
def stop(): Unit = js.native
val link: ApolloLink = js.native
val cache: ApolloCache[Shape] = js.native
val disableNetworkFetches: Boolean = js.native
val version: String = js.native
val queryDeduplication: Boolean = js.native
val defaultOptions: DefaultOptions = js.native
//val typeDefs: ApolloClientOptions<TCacheShape>['typeDefs'];
def stop(): Unit = js.native

def watchQuery[T, TVars](options: WatchQueryOptions[TVars]): ObservableQuery[T, TVars] = js.native
def query[T, TVars](options: QueryOptions[TVars]): js.Promise[ApolloQueryResult[T]] = js.native
def mutate[T, TVars](options: MutationOptions[T, TVars]): js.Promise[FetchResult[T]] = js.native
def subscribe[T, TVars](options: SubscriptionOptions[TVars]): Observable[FetchResult[T]] = js.native
def watchQuery[T, TVars](options: WatchQueryOptions[TVars]): ObservableQuery[T, TVars] = js.native
def query[T, TVars](options: QueryOptions[TVars]): js.Promise[ApolloQueryResult[T]] = js.native
def mutate[T, TVars](options: MutationOptions[T, TVars]): js.Promise[StandardFetchResult[T]] = js.native
def subscribe[T, TVars](options: SubscriptionOptions[TVars]): Observable[StandardFetchResult[T]] = js.native

// def readQuery[T, TVariables = OperationVariables](options: DataProxy.Query<TVariables>, optimistic?: boolean): T | null;
// def readFragment[T, TVariables = OperationVariables](options: DataProxy.Fragment<TVariables>, optimistic?: boolean): T | null;
// def writeQuery<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteQueryOptions<TData, TVariables>): void;
// def writeFragment<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteFragmentOptions<TData, TVariables>): void;
def readQuery[T, TVars](options: DataProxy.Query[TVars], optimistic: js.UndefOr[Boolean] = js.undefined): T | Null =
js.native
def readFragment[T, TVars](
options: DataProxy.Fragment[TVars],
optimistic: js.UndefOr[Boolean] = js.undefined): T | Null = js.native
def writeQuery[T, TVars](options: DataProxy.WriteQueryOptions[T, TVars]): Unit = js.native
def writeFragment[T, TVars](options: DataProxy.WriteFragmentOptions[T, TVars]): Unit = js.native

// def resetStore(): js.Promise<ApolloQueryResult<any>[] | null> = js.native
// def clearStore(): js.Promise<any[]> = js.native
// def onResetStore(cb: js.Function0[js.Promise[js.Any]]: js.Function0[Unit] = js.native
// def onClearStore(cb: js.Function0[js.Promise[js.Any]]: js.Function0[Unit] = js.native
// def reFetchObservableQueries(includeStandby: js.UndefOr[Boolean] = js.undefined): Promise<ApolloQueryResult<any>[]>;
// def extract(optimistic?: boolean): Shape = js.native
// def restore(serializedState: Shape): ApolloCache<Shap>;
// def addResolvers(resolvers: Resolvers | Resolvers[]): Unit = js.native
// def setResolvers(resolvers: Resolvers | Resolvers[]): Unit = js.native
// def getResolvers(): Resolvers = js.native
// def setLocalStateFragmentMatcher(fragmentMatcher: FragmentMatcher): Unit = js.native
// def setLink(newLink: ApolloLink): Unit = js.native
def resetStore(): js.Promise[js.Array[ApolloQueryResult[Any]] | Null] = js.native
def clearStore(): js.Promise[js.Array[Any]] = js.native
// def onResetStore(cb: js.Function0[js.Promise[js.Any]]: js.Function0[Unit] = js.native
// def onClearStore(cb: js.Function0[js.Promise[js.Any]]: js.Function0[Unit] = js.native
// def reFetchObservableQueries(includeStandby: js.UndefOr[Boolean] = js.undefined): Promise<ApolloQueryResult<any>[]>;
def extract(optimistic: js.UndefOr[Boolean] = js.undefined): Shape = js.native
def restore(serializedState: Shape): ApolloCache[Shape] = js.native
// def addResolvers(resolvers: Resolvers | Resolvers[]): Unit = js.native
// def setResolvers(resolvers: Resolvers | Resolvers[]): Unit = js.native
// def getResolvers(): Resolvers = js.native
// def setLocalStateFragmentMatcher(fragmentMatcher: FragmentMatcher): Unit = js.native
def setLink(newLink: ApolloLink): Unit = js.native
}
65 changes: 65 additions & 0 deletions components/apollo3/src/main/scala/cache/core/cache-module.scala
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2018 The Trapelo Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package apollo
package client3
package cache

import scala.scalajs.js
import js.|
import js.annotation._
import graphql._
import client3.utilities._
import rxjs._

@js.native
@JSImport("@apollo/client/cache/core/cache", "ApolloCache")
abstract class ApolloCache[TSerialized]() extends DataProxy {
// abstract members
def read[T, TVars](query: Cache.ReadOptions[TVars]): T | Null
def write[TResult, TVars](write: Cache.WriteOptions[TResult, TVars]): Unit
def diff[T](query: Cache.DiffOptions[T]): Cache.DiffResult[T]
def watch[TVars](watch: Cache.WatchOptions[TVars]): js.Function0[Unit]
def reset(): js.Promise[Unit]
def evict(options: Cache.EvictOptions): Boolean
def evict(
id: String,
field: js.UndefOr[String] = js.undefined,
args: js.UndefOr[js.Object | js.Dynamic] = js.undefined): Boolean
def restore(serializedState: TSerialized): ApolloCache[TSerialized]
def extract(optimistic: js.UndefOr[Boolean]): TSerialized
def removeOptimistic(id: String): Unit
def performTransaction(transaction: Transaction[TSerialized]): Unit
def recordOptimisticTransaction(transaction: Transaction[TSerialized], id: String): Unit

def transformDocument(document: DocumentNode): DocumentNode = js.native
def identify(obj: StoreObject): js.UndefOr[String] = js.native
def gc(): js.Array[String] = js.native
def transformForLink(document: DocumentNode): DocumentNode = js.native
def readQuery[QueryType, TVars](
options: DataProxy.Query[TVars],
optimistic: js.UndefOr[Boolean] = js.undefined): QueryType | Null = js.native
def readFragment[FragmentType, TVars](
options: DataProxy.Fragment[TVars],
optimistic: js.UndefOr[Boolean] = js.undefined): FragmentType | Null = js.native
def writeQuery[T, TVars](options: Cache.WriteQueryOptions[T, TVars]): Unit = js.native
def writeFragment[T, TVars](options: Cache.WriteFragmentOptions[T, TVars]): Unit = js.native
}
34 changes: 34 additions & 0 deletions components/apollo3/src/main/scala/cache/core/cache-package.scala
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018 The Trapelo Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package apollo
package client3
package cache
package core

import scala.scalajs.js
import js.|
import js.annotation._
import graphql._

trait cache_module {
type Transaction[T] = js.Function1[ApolloCache[T], Unit]
}
38 changes: 0 additions & 38 deletions components/apollo3/src/main/scala/cache/core/cache.scala

This file was deleted.

This file was deleted.

This file was deleted.

29 changes: 29 additions & 0 deletions components/apollo3/src/main/scala/cache/core/index-package.scala
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2018 The Trapelo Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package apollo
package client3
package cache
package core

import scala.scalajs.js

trait core_module extends core.cache_module with types.common_module

0 comments on commit ea2ae16

Please sign in to comment.