4.0.1 • Published 4 years ago

@gospime/apollo-client v4.0.1

Weekly downloads
49
License
MIT
Repository
github
Last release
4 years ago

Facade to create apollo client

Apollo HTTP client with response caching

Options:

const uri = `https://${hostname}:${port}${graphqlPath}`;
// options of https.Agent
const options = {
  //rejectUnauthorized: false // Skip SSL-restrictions
};

ApolloOptions: fetch-policy

const apolloOptions = {
  query: {
    // How you want your component to interact with the Apollo cache.
    // Defaults to "cache-first".
    fetchPolicy: 'no-cache',
    // How you want your component to handle network and GraphQL errors.
    // Defaults to "none", which means we treat GraphQL errors as runtime errors.
    errorPolicy: 'all',
  }
};

Example: how to execute graphql query

const Client = require('@gospime/apollo-client');

const plan = 'userSelect';
const args = { id: 2 }; // criteria to find a user
const fields = { fullname, email }; // fields to select

// calling of `query` method
Client
  .create(uri, options, apolloOptions)
  .query({ plan, args, fields })
  .then(result => console.log(result))
  .catch(error => console.error(error));

Example: how to execute graphql mutation

const Client = require('@gospime/apollo-client');

const plan = 'userEdit';
const args = { id: 2, fullname: 'new fullname' }; // find user by `id` and update the fullname

// calling of `mutate` method
Client
  .create(uri, options, apolloOptions)
  .mutate({ plan, args })
  .then(result => console.log(result))
  .catch(error => console.error(error));

Async/await example:

async () => await Client.create(uri, options, apolloOptions).mutate({ plan, args });
4.0.1

4 years ago

4.0.0

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.6.4

4 years ago

2.6.3

4 years ago

2.6.2

4 years ago

2.6.1

4 years ago

2.6.0

4 years ago

2.5.1

4 years ago

2.5.0

4 years ago

2.4.0

4 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago