Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Environment, Network, RecordSource, Store } from "relay-runtime";
import * as AbsintheSocket from "@absinthe/socket";
import { createSubscriber } from "@absinthe/socket-relay";
import { Socket as PhoenixSocket } from "phoenix";
export const tokenKey = "token";
const source = new RecordSource();
const store = new Store(source);
const fetchQueryFactory = (customHeaders = {}) => (operation, variables) =>
fetch("/graphql", {
method: "POST",
headers: {
...customHeaders,
"content-type": "application/json",
},
body: JSON.stringify({
query: operation.text, // GraphQL text from input
variables,
}),
}).then(response => {
return response.json();
});
variables,
});
}
const network = new RelayNetworkLayer(
[
urlMiddleware({
url: `${APP_BASE_PATH}/graphql`,
credentials: 'same-origin',
}),
uploadMiddleware(),
],
{ subscribeFn: networkSubscriptions },
);
const store = new Store(new RecordSource());
// Activate the read from store then network
// store.holdGC();
export const environment = new Environment({
network,
store,
});
// Components
export class QueryRenderer extends Component {
render() {
const {
variables, query, render, managedErrorTypes,
} = this.props;
return (
const createEnvironment = (
records,
fetchQuery = defaultFetchQuery,
subscribe = defaultSubscribe
) => {
const source = new Relay.RecordSource(records);
const store = new Relay.Store(source);
environment = new Relay.Environment({
network:
subscribe != null
? Relay.Network.create(fetchQuery, subscribe)
: Relay.Network.create(fetchQuery),
store,
});
// Debugging
inspector =
process.env.NODE_ENV !== 'production'
? new Relay.RecordSourceInspector(source)
: null;
return environment;
};
export function createSyncEnvironment(fetch = createFakeFetch(), records) {
return new Environment({
network: Network.create(fetch),
store: new Store(new RecordSource(records)),
});
}
import { Environment, RecordSource } from "relay-runtime";
import { createRelayEnvironment } from "coral-framework/testHelpers";
import { NETWORK_ID, NETWORK_TYPE } from "../lib/relay/localState";
import { commit } from "./SetNetworkStatusMutation";
let environment: Environment;
const source: RecordSource = new RecordSource();
beforeAll(() => {
environment = createRelayEnvironment({
source,
initLocalState: (localRecord, sourceProxy) => {
const networkRecord = sourceProxy.create(NETWORK_ID, NETWORK_TYPE);
networkRecord.setValue(false, "isOffline");
localRecord.setLinkedRecord(networkRecord, "network");
},
});
});
it("Sets comment id", () => {
commit(environment, { isOffline: true });
expect(source.get(NETWORK_ID)!.isOffline).toEqual(true);
});
beforeEach(() => {
source = new RecordSource();
environment = createRelayEnvironment({
source,
initLocalState: false,
});
});
const onComplete = () =>
observer.onCompleted()
const client = subscriptionClient
.request({ query, variables })
.subscribe(onNext, onError, onComplete)
return {
dispose: client.unsubscribe,
}
}
const network = Network.create(fetchQuery, setupSubscription)
const source = new RecordSource()
const store = new Store(source)
const environment = new Environment({
network,
store,
})
export default environment
"Content-Type": "application/json",
"User-Agent": Emission.userAgent,
"X-USER-ID": Emission.userID,
"X-ACCESS-TOKEN": Emission.authenticationToken,
"X-TIMEZONE": Constants.LocalTimeZone,
},
}),
loggerMiddleware(),
errorMiddleware({
disableServerMiddlewareTip: true,
}),
metaphysicsExtensionsLoggerMiddleware(),
timingMiddleware(),
])
const source = new RecordSource()
const store = new Store(source)
return new Environment({
network,
store,
})
}
export function getRelayEnvironment(records) {
if (environment) {
return environment
}
const source = new RecordSource(records)
const store = new Store(source)
environment = new Environment({
network,
store,
})
return environment
}
export default () => {
const fetcher = createFetcher();
const environment = new Environment({
network: Network.create(fetcher.fetch.bind(fetcher)),
store: new Store(new RecordSource())
});
const resolver = new Resolver(environment);
return {
environment,
resolver,
fetcher,
historyMiddlewares: [queryMiddleware],
fetchQuery: fetchQuery.bind(undefined, environment),
commitMutation: commitMutation.bind(undefined, environment),
commitLocalUpdate: commitLocalUpdate.bind(undefined, environment)
};
};