@simulacrum/github-api-simulator
Version:
Provides common functionality to frontend app and plugins.
74 lines • 3.74 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.toGraphql = toGraphql;
const relay_ts_1 = require("./relay.js");
function toGraphql(simulationStore, __typename, entity) {
switch (__typename) {
case "User":
// @ts-expect-error not a fully qualified return per type, TODO fill it out
return Object.assign(Object.assign(Object.assign({ __typename }, entity), toGithubRepositoryOwner(simulationStore, __typename, entity)), { name: entity.name, bio: entity.bio, createdAt: entity.createdAt, organizations(pageArgs) {
return (0, relay_ts_1.applyRelayPagination)(simulationStore.schema.organizations.selectByIds(simulationStore.store.getState(), {
ids: entity.organizations,
}), pageArgs, (org) => toGraphql(simulationStore, "Organization", org));
} });
case "Repository":
// @ts-expect-error not a fully qualified return per type, TODO fill it out
return {
name: entity.name,
description: entity.description,
nameWithOwner: entity.nameWithOwner,
login: entity.login,
url: entity.url,
createdAt: entity.createdAt,
collaborators(pageArgs) {
return (0, relay_ts_1.applyRelayPagination)(entity.collaborators, pageArgs);
},
owner(pageArgs) {
return toGraphql(simulationStore, entity.owner, pageArgs);
},
defaultBranchRef: {
name: entity.defaultBranchRef.name,
target: entity.defaultBranchRef.target,
},
languages(pageArgs) {
return (0, relay_ts_1.applyRelayPagination)(entity.languages, pageArgs, (l) => ({
name: l,
}));
},
repositoryTopics(pageArgs) {
return (0, relay_ts_1.applyRelayPagination)(entity.repositoryTopics, pageArgs, (t) => ({
topic: { name: t },
}));
},
visibility: entity.visibility,
isArchived: entity.isArchived,
};
case "Organization":
// @ts-expect-error not a fully qualified return per type, TODO fill it out
return Object.assign(Object.assign({}, toGithubRepositoryOwner(simulationStore, __typename, entity)), { __typename, id: entity.id, name: entity.name, description: entity.description, email: entity.email, createdAt: entity.createdAt, teams(pageArgs) {
return (0, relay_ts_1.applyRelayPagination)(entity.teams, pageArgs, (team) => toGraphql(simulationStore, "Team", team));
} });
default:
// @ts-expect-error not a fully qualified return per type, TODO fill it out
return entity;
}
}
/*
Represents the RepositoryOwner interface
*/
function toGithubRepositoryOwner(simulationStore, __typename, entity) {
return {
avatarUrl: entity.avatarUrl,
login: entity.login,
repositories(pageArgs) {
return (0, relay_ts_1.applyRelayPagination)(
// @ts-expect-error not a fully qualified return per type, TODO fill it out
simulationStore.schema.repositories.selectByIds(simulationStore.store.getState(), {
ids: entity.repositories,
}), pageArgs, (repository) => toGraphql(simulationStore, "Repository", repository));
},
resourcePath: entity.resourcePath,
url: entity.url,
};
}
//# sourceMappingURL=to-graphql.js.map
;