Falcon Client Configuration

Configs are stored as an object in Apollo State.

config has no schema meaning you can add anything you like.

Google Analytics Example

This example shows how to retrieve and use these configs in your components.

graphql/analytics.gql

query ANALYTICS {
config @client {
googleAnalytics {
trackerID
}
}
}

We pass our query to withApollo to access configs. This passes client as a prop:

const { client } = props;

This can then be used to query the Apollo stateL

const { config } = client.readQuery({ query: ANALYTICS }) || {};

See the full example component

import React from 'react';
import { withApollo } from '@apollo/react-hoc';
import GAnalytics from 'ganalytics';
import { ANALYTICS } from '../graphql/analytics.gql';
let ga = null;
export default WrappedComponent => {
const WithAnalytics = props => {
if (process.browser && !ga) {
const { client } = props;
const { config } = client.readQuery({ query: ANALYTICS }) || {};
const { googleAnalytics } = config || {};
const { trackerID } = googleAnalytics || {};
if (trackerID) {
ga = new GAnalytics(trackerID, {}, true);
}
}
return <WrappedComponent {...props} ga={ga} />;
};
return withApollo(WithAnalytics);
};

This same principle can used for all client configs.

Ask the community. #help

If you can't find what you're looking for, the answer might be on our community slack channel. Our team keep a close eye on this and will usually get back to you within a few hours, if not straight away. If you haven't created an account yet please sign up here slack.deity.io.