I'm developing an offline-first Expo/React Native app, using GraphQL + Apollo Client + Join Monster, and storing data in a sqlite db client-side.
My schema (and the rest of the code) looks very similar to this one https://github.com/tslater/reactnative-relay-offline/blob/master/graphql/relay-schema/index.js except instead of using Relay, I am using Apollo Client as my GraphQL client.
I have a custom networkInterface that looks like:
import schema from './graphql/relay-schema'
class LocalNetworkInterface implements NetworkInterface {
constructor(schema) {
this.schema = schema
}
query(request) {
const { query, variables } = request
return graphql(
this.schema,
printAST(query),
null,
null,
variables,
)
}
getSchema() {
return this.schema
}
}
export function createLocalNetworkInterface(options) {
const { schema } = options
return new LocalNetworkInterface(schema)
}
const networkInterface = createLocalNetworkInterface({ schema })
const client = new ApolloClient({networkInterface})
and this works well for offline queries.
However, I'm unsure of how to adapt this in order to be able to make queries against a real server when the app detects it has an internet connection. The gql query I would issue against the server is slightly different that the one I issue against the local db, if that matters. Is https://github.com/apollographql/apollo-link something that would be helpful here?