React Native SDK - sendCustomMessage method
Sends a typed message to the native tracker. At the moment the only supported type is gql, which records GraphQL operations, for example from the @openreplay/tracker-graphql Relay middleware.
Signature
Section titled Signatureimport OR from '@openreplay/react-native'
OR.sendCustomMessage('gql', JSON.stringify({
operationKind: 'query',
operationName: 'GetUser',
variables: { id: '123' },
response: { data: { user: { name: 'Demo User' } } },
duration: 85,
}))
The same function is available as OR.tracker.sendMessage(type, msg) and as the named export sendMessage (import { sendMessage } from '@openreplay/react-native').
Parameters
Section titled Parameterstype: string: The message type (only'gql'at the moment).msg: string: JSON string with the message. Forgql:operationKind,operationName,variables,responseandduration.
Using it with the GraphQL Relay middleware
Section titled Using it with the GraphQL Relay middleware@openreplay/tracker-graphql (which lists @openreplay/tracker as a peer dependency) expects a web tracker App. Pass it an object with active, timestamp and send, which forwards each GraphQL message to the React Native tracker:
import OR from '@openreplay/react-native'
import { createRelayMiddleware } from '@openreplay/tracker-graphql'
const appWrapper = {
active: () => true,
timestamp: () => Date.now(),
send: (gqlMsg) => {
const msg = JSON.stringify({
operationKind: gqlMsg[1],
operationName: gqlMsg[2],
variables: gqlMsg[3],
response: gqlMsg[4],
duration: gqlMsg[5],
})
OR.sendCustomMessage('gql', msg)
},
}
// createRelayMiddleware(sanitizer?) returns a function that takes the app
// @ts-ignore - emulating web tracker here for middleware
const middleware = createRelayMiddleware()(appWrapper)
// .. connect to relay network layer
Return value
Section titled Return valueThis method doesn’t return any values.
Have questions?
Section titled Have questions?If you have any questions about this process, feel free to reach out to us on our Slack .