Options
All
  • Public
  • Public/Protected
  • All
Menu

EF GraphQL Conversation Provider

A conversation provider for a formations connections as defined by @ef-carbon/graphql-type-conversation.

It provides a Provider class that works with the conversation Cache:

import { Cache } from '@ef-carbon/conversation';
import Provider from '@ef-carbon/conversation-provider-graphql';

// Create the provider
const provider = new Provider<string>({
  endpoint: `http://localhost:8080/graphql`,
  factory: s => s,
});

// Cache can be used with conversation APIs
const cache = new Cache<string>({ provider });

// Retrieve the start of the formation tree as defined by the server
const start = await provider.start;

// Fetch the first formation. The server will walk the tree and return future formations in the same request
const first = await cache.fetch(start);

It also exports a custom Cache that lowers the bandwidth needed by communicating previously cached entries to the server. It also allows sending the formation walker options to the server which can help requests determine future formations the server should send back to the cache:

import { Cache } from '@ef-carbon/conversation-provider-graphql';

// Create the cache. Can be used with formation APIs
const cache = new Cache<string>({
  endpoint: `http://localhost:8080/graphql`,
  factory: s => s,
});

// The start of the formation tree as defined by the server
const start = await cache.start;

// Perform a customised population of the cache
const first = await cache.fetch(start, {
  maximum: 128,                                   // Fetch up to 128 formations
  end: 'a0751376-9060-4ef2-8f9d-db6acf6bf4cb',    // Only send up to this GUID
  skip: ['d1125059-14b8-42b3-9bb1-d582bc1f759c'], // Skip sending this GUID back from the server
});