Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const {
Environment,
Network,
RecordSource,
Store,
} = require('relay-runtime')
import '../global'
import { graphql, printSchema } from 'graphql'
import schema from '../graphql/relay-schema/index.js'
// console.log('schemmmas',printSchema(schema))
const store = new Store(new RecordSource())
const network = Network.create((operation, variables) =>
graphql(schema, operation.text, null, {}, variables)
)
const environment = new Environment({
network,
store,
})
export default environment
query: operation.text,
variables,
}),
})).json();
if (!jsonPayload.errors) {
// always save the valid response (probably not needed during cache "force")
await cache.set(query, variables, jsonPayload);
}
return jsonPayload;
};
return new PartialErrorsEnvironment(
{
network: Network.create(fetchQuery),
store: new Store(new RecordSource()),
},
onPartialError,
);
}
`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 types = error ? map(e => e.name, error) : [];
// Update cache on queries
if (isQuery && json) {
cache.set(queryID, variables, json);
}
// Clear cache on mutations
if (isMutation) {
cache.clear();
}
return json;
});
}
export const modernEnvironment = new Environment({
network: Network.create(fetchQuery),
store: new Store(new RecordSource()),
});
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,
})
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
}
import { API, graphqlOperation } from 'aws-amplify';
import { Environment, Network, RecordSource, Store } from 'relay-runtime';
function fetchQuery(operation, variables) {
return API.graphql(graphqlOperation(operation.text, variables));
}
function subscribe(operation, variables) {
return API.graphql(graphqlOperation(operation.text, variables)).map(({value})=>value);
}
const environment = new Environment({
network: Network.create(fetchQuery, subscribe),
store: new Store(new RecordSource()),
});
export default environment;
interface Props {
relay?: RelayProp
}
export class RelayStubProvider extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
relay: PropTypes.object,
}
static defaultProps = {
relay: {
environment: new Environment({
network: Network.create(x => x),
store: new Store(new RecordSource()),
}),
variables: {},
},
}
static childContextTypes = {
relay: PropTypes.object.isRequired,
}
getChildContext() {
return {
relay: this.props.relay,
}
}
render() {
import { Environment, Network, RecordSource, Store } from "relay-runtime";
const store = new Store(new RecordSource());
const network = Network.create((operation, variables) => {
return fetch("http://127.0.0.1:8000/graphql/", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
query: operation.text,
variables
})
}).then(response => {
return response.json();
});
});