Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
);
const authMiddleware = new ApolloLink((operation, forward) => {
operation.setContext({
headers: { 'Authorization': localStorage.getItem('Auth0IdToken') || '' }
});
return forward(operation);
});
const link = ApolloLink.split(
this.isSubscription,
/* if true use */ websocket,
/* if false use */ http,
);
return concat(authMiddleware, link);
}
})
const authMiddleware = new ApolloLink((operation, forward)=> {
if (appJWTToken) {
operation.setContext({
headers: {
Authorization: `Bearer ${appJWTToken}`
}
});
}
return forward(operation);
})
const apolloClient = new ApolloClient({
link: logoutLink.concat(concat(authMiddleware, httpLink)),
cache: new InMemoryCache(),
});
const App = ({ accessToken }) => {
let previousToken = appJWTToken;
appJWTToken = accessToken.token
return (
{({loading, error, data, refetch}) => {
// refetch if token has changed
if (!previousToken && (previousToken !== appJWTToken)) {
refetch()
}
if (config.uri) {
config.httpLinkOptions.uri = config.uri;
} else {
// Allow GRAPHQL_ENDPOINT to be changed
config.httpLinkOptions.uri = config.httpLinkOptions.uri
? config.httpLinkOptions.uri
: GRAPHQL_ENDPOINT;
}
const uploadLink = createUploadLink(config.httpLinkOptions);
// We define the HTTP Link
const httpLink = createHttpLink(config.httpLinkOptions);
if (!config.disableMeteorAccounts) {
terminatingLink = ApolloLink.concat(meteorAccountsLink, uploadLink, httpLink);
} else {
terminatingLink = ApolloLink.concat(uploadLink, httpLink);
}
// A chance to add change the links
terminatingLink = Config.getLink(terminatingLink);
if (!config.disableWebsockets) {
wsLink = new WebSocketLink({
uri: config.httpLinkOptions.uri.replace(/http/, 'ws'),
options: {
reconnect: true,
connectionParams: () => ({
[AUTH_TOKEN_KEY]: localStorage.getItem('Meteor.loginToken'),
}),
},
export var createClient = function createClient(httpLink) {
// Add the authorization to the headers
var authMiddleware = new ApolloLink(function (operation, forward) {
operation.setContext({
headers: {
authorization: localStorage.getItem('user-token') || null
}
});
return forward(operation);
});
return new ApolloClient({
link: concat(authMiddleware, httpLink),
cache: new InMemoryCache({
dataIdFromObject: function dataIdFromObject(object) {
return object.id;
},
fragmentMatcher: fragmentMatcher
}),
clientState: {}
});
};
export var WPProvider = function WPProvider(_ref) {
operation.setContext({
headers: {
authorization: getToken(),
}
})
return forward(operation);
})
const httpLink = new HttpLink({
uri: 'https://my-app.herokuapp.com/v1/graphql', // Server URL (must be absolute)
credentials: 'same-origin' // Additional fetch() options like `credentials` or `headers`
})
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
link: concat(authMiddleware, httpLink),
cache: new InMemoryCache().restore(initialState || {})
})
}
const wsLink = new WebSocketLink({
uri: ws,
options: {
reconnect: true
}
})
const authMiddleware = new ApolloLink((operation, forward) => {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
authorization: localStorage.getItem('TOKEN') || null
}
}))
return forward(operation)
})
const linkWithMiddleware = concat(authMiddleware, httpLink)
const link = split(
({ query }) => {
const { kind, operation } = getMainDefinition(query)
return kind === 'OperationDefinition' && operation === 'subscription'
},
wsLink,
linkWithMiddleware
)
const cache = new InMemoryCache()
const client = new ApolloClient({
link,
cache
})
const root = document.getElementById('root')
operation.setContext({
headers: {
authorization: token ? `Bearer ${token}` : "",
}
});
return forward(operation).map(response => {
if (response.errors !== undefined && response.errors.length > 0) {
response.data.errors = response.errors;
}
return response;
});
});
const client = new ApolloClient({
link: concat(authMiddleware, httpLink),
//link: authLink.concat(link),
cache: cache,
});
/*
export default (
({ children }) => (
{children}
)
);
*/
class ApolloProviderGithub extends Component {
constructor(props) {
super(props);
const httpLink = createHttpLink({ uri: "https://api.github.com/graphql" });
const authMiddleware = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
authorization: localStorage.getItem("token")
? `Bearer ${localStorage.getItem("token")}`
: null
}
});
return forward(operation);
});
const apolloClient = new ApolloClient({
link: concat(authMiddleware, httpLink),
cache: new InMemoryCache()
});
export default apolloClient;
export const createRtdbLink = ({database}: {database: firebaseDatabase.Database}) => {
return concat(new RtdbQueryLink({database}), new RtdbSubLink({database}));
};
export const compositeQueueLink = (config: DataSyncConfig, filter?: TYPE_MUTATION): ApolloLink => {
const offlineLink = new OfflineQueueLink(config, filter);
offlineLink.openQueueOnNetworkStateUpdates();
const localLink = new LocalDirectiveFilterLink();
return concat(offlineLink, localLink);
};