Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump url-parse from 1.5.3 to 1.5.10 #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
"apollo-server": "^2.25.3",
"apollo-server-express": "^2.4.8",
"apollo-upload-client": "^14.1.3",
"auth0": "^2.27.1",
"auth0-get-all-users": "^1.1.0",
"babel-loader": "^8.0.5",
"body-parser": "^1.18.3",
"cross-fetch": "^3.0.6",
Expand Down
8 changes: 4 additions & 4 deletions src/remoteTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import extractFiles from 'extract-files/public/extractFiles';
// HTTP requests
//

function makeExecutor(httpEndpoint) {
function makeExecutor(httpEndpoint, prefix) {
return async function executor({ document, variables, context }) {
const allowedHeaders = Object.keys(context?.headers || {})
.filter((name) => name.toLowerCase().substr(0, 2) === 'x-')
.filter((name) => name.toLowerCase().startsWith(prefix))
.reduce((accum, name) => ({ ...accum, [name]: context?.headers[name] }), {});

const query = print(document);
Expand Down Expand Up @@ -118,10 +118,10 @@ function makeSubscriber(wsEndpoint) {
};
}

export default function makeRemoteTransport(httpEndpoint, wsEndpoint) {
export default function makeRemoteTransport(httpEndpoint, wsEndpoint, prefix="x-") {

return {
executor: makeExecutor(httpEndpoint),
executor: makeExecutor(httpEndpoint, prefix),
subscriber: wsEndpoint ? makeSubscriber(wsEndpoint) : undefined,
};
}
118 changes: 118 additions & 0 deletions src/remotes/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { wrapSchema, introspectSchema } from '@graphql-tools/wrap';
import makeRemoteTransport from '../remoteTransport';
import { delegateToSchema } from '@graphql-tools/delegate';
import { TransformQuery } from '@graphql-tools/wrap';
import { Kind } from 'graphql';

function getConnectionTypes(prefix) {
return `
extend type ${prefix}Badge {
details: CmsBadge
}

extend type ${prefix}User {
sites: [CmsSite]
}
`;
}

function getConnectionResolvers(prefix, schemas) {
return {
[`${prefix}Badge`]: {
details: {
selectionSet: '{ id }',
async resolve(parent, args, context, info) {
return delegateToSchema({
schema: schemas.cms,
operation: 'query',
fieldName: 'badgeCollection',
args: {
where: {
id: parent.id,
},
limit: 1,
},
context,
info,
transforms: [
new TransformQuery({
path: ['badgeCollection'],
queryTransformer: (subtree) => ({
kind: Kind.SELECTION_SET,
selections: [
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: 'items',
},
selectionSet: subtree,
},
],
}),
resultTransformer: (r) => r?.items[0],
}),
],
});
},
},
},
[`${prefix}User`]: {
sites: {
selectionSet: '{ roles }',
async resolve(parent, args, context, info) {
return delegateToSchema({
schema: schemas.cms,
operation: 'query',
fieldName: 'siteCollection',
args: {
where: {
OR: [...parent.roles.map((role) => {
if (role.name == "Staff") return { type: "Volunteer" };
return { type: role.name };
}), { type: "Student" }]
}
},
context,
info,
transforms: [
new TransformQuery({
path: ['siteCollection'],
queryTransformer: (subtree) => ({
kind: Kind.SELECTION_SET,
selections: [
{
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: 'items',
},
selectionSet: subtree,
},
],
}),
resultTransformer: (r) => r?.items,
}),
],
});
},
},
},
};
}

export default async function createAccountSchema(uri, wsUri) {
console.log(` * account(${uri})`);
const { executor, subscriber } = makeRemoteTransport(uri, wsUri, "");
const schema = wrapSchema({
schema: await introspectSchema(executor),
executor,
subscriber,
});
return {
schema,
transforms: [],
getConnectionTypes,
getConnectionResolvers,
};
}
Loading