question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for local typeDefs and resolvers

See original GitHub issue

I’m using a local GraphQL schema with client-only queries to achieve local state management using Apollo.

Since ApolloClient gets initialized by Offix itself, and there is no way to provide additional typeDefs and resolver options in the config I’m wondering if this is even possible using Offix?

Here is an example of the options I need that can’t be offered to Offix’ OfflineClient:

const apolloClient = new ApolloClient({
  typeDefs,
  resolvers,
});

Ideally, it should be possible to pass a client initializer function which allows you to create an ApolloClient from outside OfflineClient.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
wilmervanheerdecommented, Nov 29, 2019

Thanks for picking this up so early, the new changes look awesome!

1reaction
darahayescommented, Nov 29, 2019

Hey @wilmervanheerde so sorry for taking this long to get back to you. Your issue actually motivated us to go ahead and do some work that we’ve been planning on doing for a long time.

Previously, the OfflineClient class was a wrapper that would internally create an ApolloClient and then you could get access to it afterwards. The flow looked something like this.

const offlineClient = new OfflineClient(options)
const apolloClient = await offlineClient.init()

And of course, your issue was that you wanted to pass some additional options into the resulting ApolloClient but our API didn’t provide a way to do that.

Well, we’ve refactored things so now we export a class called ApolloOfflineClient which directly extends ApolloClient. Now you can pass in all of the Apollo Client options you’d like.

The way you initialise things is slightly different, mainly, you need to pass an ApolloLink that can talk to your GraphQL server. Check out the example code below.

import { ApolloOfflineClient } from 'offix-client'

const link = new HttpLink({ uri: 'http://localhost/graphql' })
  
const config = {
  link,
  typeDefs,
  resolvers,
  ...otherOptions
}

const client = new ApolloOfflineClient(config)
await client.init()
...

// `client` is an ApolloClient so you can call all of the methods you'd expect
client.query(...)
client.mutate(...)
client.offlineMutate(...)

We haven’t officially released it yet and we’re still working on some docs updates but you should be able to try out our dev release with npm install offix-client@0.11.0-dev3. We’d love to get your feedback to see if it resolves your problem (and hopefully doesn’t create any new ones) before we cut an official release. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Local resolvers - Apollo GraphQL Docs
Apollo Client supports asynchronous local resolver functions. These functions can either be async functions or ordinary functions that return a Promise .
Read more >
Using TypeGraphQL to generate typedefs and resolvers for ...
I would like to use TypeGraphQL with Apollo local state in browser. How can I use TypeGraphQL to generate typedefs and resolvers for...
Read more >
Support for client side resolvers (apollo-link-state) #197 - GitHub
I haven't found it useful as apollo-link-state has no typedef, so declaring graphql types makes no sense here.
Read more >
Schema Merging – GraphQL Tools
This is useful for building a single local service schema from many ... GraphQLSchema objects together with extra typeDefs and resolvers .
Read more >
GraphQL Schemas, TypeDefs & Resolvers - Prisma
GraphQL has a clear separation of structure and behaviour. The structure of a GraphQL server is — as we just discussed — its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found