moved apollo cache in seperate file
This commit is contained in:
parent
615292ac24
commit
1683c0d467
55
src/Cache.ts
Normal file
55
src/Cache.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import { InMemoryCache } from "@apollo/client"
|
||||||
|
import ObjID from "./types/ObjID"
|
||||||
|
|
||||||
|
const cache = new InMemoryCache({
|
||||||
|
typePolicies:{
|
||||||
|
File:{
|
||||||
|
fields:{
|
||||||
|
id:{
|
||||||
|
merge(_,incomming){
|
||||||
|
// HACK: i use the merge function to change the id from a string to ObjID object.
|
||||||
|
// afaik apollo does not yet support custom scalar types.
|
||||||
|
if (!incomming){
|
||||||
|
return incomming
|
||||||
|
}else if (incomming instanceof ObjID){
|
||||||
|
return incomming
|
||||||
|
}else{
|
||||||
|
return ObjID.fromString(incomming as string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Directory:{
|
||||||
|
fields:{
|
||||||
|
id:{
|
||||||
|
merge(_,incomming){
|
||||||
|
if (!incomming){
|
||||||
|
return incomming
|
||||||
|
}else if (incomming instanceof ObjID){
|
||||||
|
return incomming
|
||||||
|
}else{
|
||||||
|
return ObjID.fromString(incomming as string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Query: {
|
||||||
|
fields: {
|
||||||
|
files: {
|
||||||
|
merge(existing, incoming){
|
||||||
|
return incoming
|
||||||
|
}
|
||||||
|
},
|
||||||
|
directorys:{
|
||||||
|
merge(existing, incoming){
|
||||||
|
return incoming
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default cache
|
@ -2,62 +2,13 @@ import React from "react"
|
|||||||
import ReactDOM from "react-dom"
|
import ReactDOM from "react-dom"
|
||||||
import "./index.scss"
|
import "./index.scss"
|
||||||
import App from "./App"
|
import App from "./App"
|
||||||
import { ApolloClient, ApolloProvider, InMemoryCache } from "@apollo/client"
|
import { ApolloClient, ApolloProvider } from "@apollo/client"
|
||||||
import "react-contexify/dist/ReactContexify.css"
|
import "react-contexify/dist/ReactContexify.css"
|
||||||
import ObjID from "./types/ObjID"
|
import cache from "./Cache"
|
||||||
|
|
||||||
const client = new ApolloClient({
|
const client = new ApolloClient({
|
||||||
uri: "/api/graphql",
|
uri: "/api/graphql",
|
||||||
cache: new InMemoryCache({
|
cache: cache,
|
||||||
typePolicies:{
|
|
||||||
File:{
|
|
||||||
fields:{
|
|
||||||
id:{
|
|
||||||
merge(_,incomming){
|
|
||||||
// HACK: i use the merge function to change the id from a string to ObjID object.
|
|
||||||
// afaik apollo does not yet support custom scalar types.
|
|
||||||
if (!incomming){
|
|
||||||
return incomming
|
|
||||||
}else if (incomming instanceof ObjID){
|
|
||||||
return incomming
|
|
||||||
}else{
|
|
||||||
return ObjID.fromString(incomming as string)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Directory:{
|
|
||||||
fields:{
|
|
||||||
id:{
|
|
||||||
merge(_,incomming){
|
|
||||||
if (!incomming){
|
|
||||||
return incomming
|
|
||||||
}else if (incomming instanceof ObjID){
|
|
||||||
return incomming
|
|
||||||
}else{
|
|
||||||
return ObjID.fromString(incomming as string)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Query: {
|
|
||||||
fields: {
|
|
||||||
files: {
|
|
||||||
merge(existing, incoming){
|
|
||||||
return incoming
|
|
||||||
}
|
|
||||||
},
|
|
||||||
directorys:{
|
|
||||||
merge(existing, incoming){
|
|
||||||
return incoming
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Disable drag and drop behaviour on document
|
// Disable drag and drop behaviour on document
|
||||||
|
Loading…
Reference in New Issue
Block a user