Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Update user's data
user.firstName = data.firstName;
user.lastName = data.lastName;
await user.save();
}
try {
await authPlugin.createUser({ data: args.data, user, permanent: true }, context);
result.authUser = true;
} catch {
// Update firstName/lastName, but do not touch the existing password
await authPlugin.updateUser({ data: omit(args.data, ["password"]), user }, context);
}
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(result);
};
publishRevision: (_: any, args: Object, ctx: Object, info: Object) => {
args.data = { published: true };
return resolveUpdate(pageFetcher)(_, args, ctx, info);
},
// Delete a revision
// Creates a revision from the given revision
createRevisionFrom: createRevisionFrom,
// Updates revision
updateRevision: resolveUpdate(pageFetcher),
// Publish revision (must be given an exact revision ID to publish)
publishRevision: (_: any, args: Object, ctx: Object, info: Object) => {
args.data = { published: true };
return resolveUpdate(pageFetcher)(_, args, ctx, info);
},
// Delete a revision
deleteRevision: resolveDelete(pageFetcher),
// Creates a new element
createElement: resolveCreate(elementFetcher),
// Updates an element
updateElement: resolveUpdate(elementFetcher),
// Deletes an element
deleteElement: resolveDelete(elementFetcher)
},
PbPageSettings: {
_empty: () => ""
}
}
};
return await resolver.resolve(root, args, context, info);
},
oembedData: oembed
},
PbMutation: {
// Creates a new page
createPage: resolveCreate(pageFetcher),
// Deletes the entire page
deletePage: resolveDelete(pageFetcher),
// Sets given page as home page.
setHomePage,
// Creates a revision from the given revision
createRevisionFrom: createRevisionFrom,
// Updates revision
updateRevision: resolveUpdate(pageFetcher),
// Publish revision (must be given an exact revision ID to publish)
publishRevision: (_: any, args: Object, ctx: Object, info: Object) => {
args.data = { published: true };
return resolveUpdate(pageFetcher)(_, args, ctx, info);
},
// Delete a revision
deleteRevision: resolveDelete(pageFetcher),
// Creates a new element
createElement: resolveCreate(elementFetcher),
// Updates an element
updateElement: resolveUpdate(elementFetcher),
// Deletes an element
deleteElement: resolveDelete(elementFetcher)
},
PbPageSettings: {
resolvers: {
FormsQuery: {
getForm: resolveGet(getForm),
listForms,
listPublishedForms,
getPublishedForm
},
FormsMutation: {
// Creates a new form
createForm: resolveCreate(getForm),
// Deletes the entire form
deleteForm: resolveDelete(getForm),
// Creates a revision from the given revision
createRevisionFrom: createRevisionFrom,
// Updates revision
updateRevision: resolveUpdate(getForm),
// Publish revision (must be given an exact revision ID to publish)
publishRevision: (_: any, args: Object, ctx: Object) => {
args.data = { published: true };
return resolveUpdate(getForm)(_, args, ctx);
},
unpublishRevision: (_: any, args: Object, ctx: Object) => {
args.data = { published: false };
return resolveUpdate(getForm)(_, args, ctx);
},
// Delete a revision
deleteRevision: resolveDelete(getForm),
saveFormView
}
}
# Logs a view of a form
saveFormView(id: ID!): SaveFormViewResponse
}
`,
resolvers: {
FormsQuery: {
getForm: resolveGet(getForm),
listForms,
listPublishedForms,
getPublishedForm
},
FormsMutation: {
// Creates a new form
createForm: resolveCreate(getForm),
// Deletes the entire form
deleteForm: resolveDelete(getForm),
// Creates a revision from the given revision
createRevisionFrom: createRevisionFrom,
// Updates revision
updateRevision: resolveUpdate(getForm),
// Publish revision (must be given an exact revision ID to publish)
publishRevision: (_: any, args: Object, ctx: Object) => {
args.data = { published: true };
return resolveUpdate(getForm)(_, args, ctx);
},
unpublishRevision: (_: any, args: Object, ctx: Object) => {
args.data = { published: false };
return resolveUpdate(getForm)(_, args, ctx);
},
// Delete a revision
getHomePage,
getNotFoundPage,
getErrorPage,
listElements: resolveList(elementFetcher),
searchTags: async (root: any, args: Object, context: Object, info: Object) => {
const resolver = context.plugins.byName("pb-resolver-search-tags");
return await resolver.resolve(root, args, context, info);
},
oembedData: oembed
},
PbMutation: {
// Creates a new page
createPage: resolveCreate(pageFetcher),
// Deletes the entire page
deletePage: resolveDelete(pageFetcher),
// Sets given page as home page.
setHomePage,
// Creates a revision from the given revision
createRevisionFrom: createRevisionFrom,
// Updates revision
updateRevision: resolveUpdate(pageFetcher),
// Publish revision (must be given an exact revision ID to publish)
publishRevision: (_: any, args: Object, ctx: Object, info: Object) => {
args.data = { published: true };
return resolveUpdate(pageFetcher)(_, args, ctx, info);
},
// Delete a revision
deleteRevision: resolveDelete(pageFetcher),
// Creates a new element
createElement: resolveCreate(elementFetcher),
createRevisionFrom: createRevisionFrom,
// Updates revision
updateRevision: resolveUpdate(getForm),
// Publish revision (must be given an exact revision ID to publish)
publishRevision: (_: any, args: Object, ctx: Object) => {
args.data = { published: true };
return resolveUpdate(getForm)(_, args, ctx);
},
unpublishRevision: (_: any, args: Object, ctx: Object) => {
args.data = { published: false };
return resolveUpdate(getForm)(_, args, ctx);
},
// Delete a revision
deleteRevision: resolveDelete(getForm),
saveFormView
}
}
};
// Deletes the entire page
deletePage: resolveDelete(pageFetcher),
// Sets given page as home page.
setHomePage,
// Creates a revision from the given revision
createRevisionFrom: createRevisionFrom,
// Updates revision
updateRevision: resolveUpdate(pageFetcher),
// Publish revision (must be given an exact revision ID to publish)
publishRevision: (_: any, args: Object, ctx: Object, info: Object) => {
args.data = { published: true };
return resolveUpdate(pageFetcher)(_, args, ctx, info);
},
// Delete a revision
deleteRevision: resolveDelete(pageFetcher),
// Creates a new element
createElement: resolveCreate(elementFetcher),
// Updates an element
updateElement: resolveUpdate(elementFetcher),
// Deletes an element
deleteElement: resolveDelete(elementFetcher)
},
PbPageSettings: {
_empty: () => ""
}
}
};
resolvers: {
PbPage: {
createdBy(page) {
return { __typename: "SecurityUser", id: page.createdBy };
},
updatedBy(page) {
return { __typename: "SecurityUser", id: page.updatedBy };
}
},
PbElement: {
preview({ preview }) {
return preview ? { __typename: "File", id: preview } : null;
}
},
PbQuery: {
getPage: resolveGet(pageFetcher),
listPages: listPages,
listPublishedPages,
getPublishedPage,
getHomePage,
getNotFoundPage,
getErrorPage,
listElements: resolveList(elementFetcher),
searchTags: async (root: any, args: Object, context: Object, info: Object) => {
const resolver = context.plugins.byName("pb-resolver-search-tags");
return await resolver.resolve(root, args, context, info);
},
oembedData: oembed
},
PbMutation: {
// Creates a new page