Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GraphQLConfig

A helper class, that handles user authentication over http and web socket connections. It exposes properties that make it easier to setup an Apollo client to communicate with the Realm Object Server GraphQL API.

Note: A single configuration is valid for a single Realm path.

example

const config = await GraphQLConfig.create(user, '/~/foo');

const httpLink = ApolloLink.concat(
  config.authLink,
  new HttpLink({ uri: config.httpEndpoint }));

const subscriptionLink = new WebSocketLink({
  uri: config.webSocketEndpoint,
  options: {
    connectionParams: config.connectionParams
  }
});

// Hybrid mode - subscriptions go over websocket,
// queries and mutations - over http.
const link = split(({ query }) => {
    const { kind, operation } = getMainDefinition(query);
    return kind === 'OperationDefinition' && operation === 'subscription';
  },
  subscriptionLink,
  httpLink);

client = new ApolloClient({
  link: link,
  cache: new InMemoryCache()
});

Hierarchy

  • GraphQLConfig

Index

Properties

authLink

authLink: ApolloLink
readonly

An ApolloLink that handles setting the Authorization header on HTTP request (query and mutation operations). Compose this with an HttpLink by calling ApolloLink.concat or ApolloLink.from.

example

const httpLink = ApolloLink.concat(
  config.authLink,
  new HttpLink({ uri: config.httpEndpoint }));
see

Composing Links section in the Apollo Client docs.

see

HttpLink docs.

connectionParams

connectionParams: function
readonly

A function that generates the connection params that are sent to the ROS GraphQL subscription API. They contain the access token used to authenticate the connection.

Note: do not invoke the function but instead pass the property directly to the SubscriptionClient's options. This way, the client will be able to invoke it every time a connection is established, thus providing a valid access token every time.

example

const subscriptionLink = new WebSocketLink({
  uri: config.webSocketEndpoint,
  options: {
    connectionParams: config.connectionParams
  }
});
see

WebSocket Link docs.

Type declaration

    • (): any
    • Returns any

httpEndpoint

httpEndpoint: string
readonly

The http endpoint of the ROS GraphQL API. This is provided for convenience and always resolves to http://path-to-ros:port/graphql/realmPath.

example

const httpLink = createHttpLink({
  uri: config.httpEndpoint
});
see

HttpLink docs.

webSocketEndpoint

webSocketEndpoint: string
readonly

The websocket endpoint of the ROS GraphQL subscription API. This is provided for convenience and always resolves to ws://path-to-ros:port/graphql/realmPath.

example

const subscriptionLink = new WebSocketLink({
  uri: config.webSocketEndpoint,
  options: {
    connectionParams: config.connectionParams
  }
});
see

WebSocket Link docs.

Methods

Static create

  • create(user: User, realmPath: string, authErrorHandler?: function): Promise<GraphQLConfig>
  • Creates a new GraphQLConfig instance, that contains helper properties that can be used to configure the Apollo client.

    Parameters

    • user: User

      A valid logged-in User.

    • realmPath: string

      The relative path for the Realm on the server. If the path contains ~, it will be replaced with the user's Id (this will not work if the user was logged in with Credentials.anonymous).

    • Optional authErrorHandler: function

      An error handler that will be invoked if there are problems with refreshing the user's access token (which can happen either because they lost access to the Realm or due to network issues). If you return true, the error will be considered fatal and the request will not be retried. Otherwise, a retry will be attempted after 3 seconds.

        • (error: any): boolean
        • Parameters

          • error: any

          Returns boolean

    Returns Promise<GraphQLConfig>

    A Promise, that, when resolved, contains a fully configured GraphQLConfig instance.