Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
method: 'POST',
headers: {
// Add authentication and other headers here
'content-type': 'application/json'
},
body: JSON.stringify({
queryId: operation.id,
variables,
}),
}).then(response => {
return response.json();
});
}
const environment = new Environment({
network: Network.create(fetchQuery),
store: new Store(new RecordSource()),
});
export default environment;
const subscriptionClient = new SubscriptionClient(
`ws${window.location.protocol === 'https:' ? 's' : ''}://${
window.location.host
}/graphql`,
{
reconnect: true,
},
);
const subscriptionLink = new WebSocketLink(subscriptionClient);
networkSubscriptions = (operation, variables) => execute(subscriptionLink, {
query: operation.text,
variables,
});
}
export const environment = new Environment({
network: Network.create(networkFetch, networkSubscriptions),
store: new Store(new RecordSource()),
});
// Components
export class QueryRenderer extends Component {
render() {
const {
variables, query, render, managedErrorTypes,
} = this.props;
return (
{
const { error } = data;
const response = await fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: operation.text,
variables,
}),
});
return response.json();
}
const modernEnvironment: Environment = new Environment({
network: Network.create(fetchQuery),
store: new Store(new RecordSource()),
});
const rootElement = document.getElementById('root');
if (rootElement) {
ReactDOM.render(
export default function initEnvironment({ records = {} } = {}) {
// Create a network layer from the fetch function
const network = Network.create(fetchQuery)
const store = new Store(new RecordSource(records))
// Make sure to create a new Relay environment for every server-side request so that data
// isn't shared between connections (which would be bad)
if (typeof window === 'undefined') {
return new Environment({
network,
store,
})
}
// reuse Relay environment on client-side
if (!relayEnvironment) {
relayEnvironment = new Environment({
network,
store,
const response = await fetch(GRAPHQL_URL, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: getAccessToken(),
},
body: JSON.stringify({
query: operation.text,
variables,
}),
});
return await response.json();
};
const network = Network.create(RelayNetworkLogger.wrapFetch(fetchQuery, () => ''), setupSubscription);
const source = new RecordSource();
const store = new Store(source);
const env = new Environment({
network,
store,
});
export default env;
return fetch("/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query: operation.text,
variables,
}),
}).then(response => {
return response.json()
})
}
const modernEnvironment = new Environment({
network: Network.create(fetchQuery),
store: new Store(new RecordSource()),
})
ReactDOM.render(
,
mountNode,
)
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)
};
};
networkHeaders[authHeaderKey] = accessToken;
}
const fetchQuery = (operation, variables): Promise => {
return Observable.create(observer => {
if (operation.operationKind !== 'mutation') {
asyncStoreRead(observer, operation, variables);
}
if (ConnectionManager.isConnected()) {
fetchFromTheNetwork(networkHeaders, operation, variables, observer);
}
});
};
return new Environment({
network: Network.create(fetchQuery),
store,
});
}
export function createResolver(fetcher) {
const environment = new Environment({
network: Network.create((...args) => fetcher.fetch(...args)),
store: new Store(new RecordSource()),
});
return new Resolver(environment);
}
export const initEnvironment = ({ records = {} } = {}) => {
const network = Network.create(fetchQuery);
const store = new Store(new RecordSource(records));
if (!process.browser) {
return new Environment({
network,
store
});
}
if (!environment) {
environment = new Environment({
network,
store
});
}