Currently, I have a GraphQL service endpoint that is accessed through a lambda function on a remote server. Access is restricted to clients from a known authorized host.
I would like to make the client open-source, but I don’t want to allow any locally hosted development client to access the GraphQL interface, due to transaction restrictions. Instead, I would like a locally running client to have access to a limited set of data cached in the browser’s local storage.
One thought would be to configure the client like so:
const isKnownHost = window.location.href === KNOWN_HOST
const client = new ApolloClient({
link: isKnownHost? authLink.concat(httpLink) : null, // is this even valid?
cache: new InMemoryCache(/*locally cached values set up here*/),
});
Then, at runtime, use queries where all fields are local, so instead of:
const GET_OPENING_ADDITIONAL = gql`
query getOpeningAdditional($fen: String!, $sites: [String]!) {
getOpeningAdditional(fen: $fen, sites: $sites) {
alsoKnownAs
wins {
w
b
d
}
}
}
`;
the local client would use (ignore syntax errors):
const GET_OPENING_ADDITIONAL = gql`
query getOpeningAdditional($fen: String!, $sites: [String]!) {
getOpeningAdditional(fen: $fen, sites: $sites) {
alsoKnownAs @client
wins @client {
w
b
d
}
}
}
`;
Am I on the right track? Is there an alternative approach that’s less messy?