Skip to content

Commit

Permalink
Fixed alive method
Browse files Browse the repository at this point in the history
  • Loading branch information
Fgerthoffert committed Jul 5, 2021
1 parent 81150c8 commit d2c9e8b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/utils/graphql/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ApolloClient from 'apollo-client';
import { ApolloLink } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import fetch from 'node-fetch';
import {Base64} from 'js-base64'

import { ConfigFlags } from '../../../global';

Expand All @@ -16,15 +17,15 @@ const graphqlClient = async (cmdConfig: ConfigFlags) => {
const authMiddleware = new ApolloLink((operation: any, forward: any) => {
operation.setContext({
headers: {
authorization: `Basic ${cmdConfig.jahiaAdminUsername}:${cmdConfig.jahiaAdminPassword}`,
Origin: cmdConfig.jahiaAdminUrl
authorization: `Basic ${Base64.btoa(cmdConfig.jahiaAdminUsername + ':' + cmdConfig.jahiaAdminPassword)}`
},
});
return forward(operation).map(
(response: {
errors: Array<object> | undefined;
data: { errors: Array<object> };
}) => {
console.log(JSON.stringify(response))
if (response.errors !== undefined && response.errors.length > 0) {
response.data.errors = response.errors;
}
Expand All @@ -33,7 +34,20 @@ const graphqlClient = async (cmdConfig: ConfigFlags) => {
);
});

const link = ApolloLink.from([authMiddleware, httpLink]);
const refererMiddleware = new ApolloLink((operation, forward) => {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
referer: cmdConfig.jahiaAdminUrl,
}
}));

return forward(operation);
})

const link = ApolloLink.from([authMiddleware, refererMiddleware, httpLink]);

console.log(link)

return new ApolloClient({
link,
Expand Down

0 comments on commit d2c9e8b

Please sign in to comment.