Skip to content

Commit 638928e

Browse files
committed
Setup for tutorial mutation
1 parent 81d9c22 commit 638928e

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

packages/gatsby-theme/gatsby-node.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// const componentWithMDXScope = require('gatsby-mdx/component-with-mdx-scope');
22
const {
33
getTutorialSlug,
4-
getTutorialOverviewSlug
5-
} = require("./src/utils/getTutorialSlug.js");
4+
getTutorialOverviewSlug,
5+
} = require('./src/utils/getTutorialSlug.js');
6+
7+
const { Mutation } = require('react-apollo');
8+
const { gql } = require('graphql-tag');
69

710
exports.createPages = async ({ graphql, actions }) => {
811
const { createPage } = actions;
912
const TutorialLayout = require.resolve(
10-
`./src/components/templates/Tutorial.tsx`
13+
`./src/components/templates/Tutorial.tsx`,
1114
);
1215

1316
const { data } = await graphql(`
@@ -29,11 +32,29 @@ exports.createPages = async ({ graphql, actions }) => {
2932
}
3033
`).catch(error => console.error(error));
3134

35+
const UPSERT_TUTORIAL = gql`
36+
mutation UpsertTutorial(
37+
$gatsbyID: String!
38+
$name: String!
39+
$numberofChapters: Int!
40+
) {
41+
upsertTutorial(
42+
gatsbyId: $gatsbyID
43+
name: $name
44+
numberofChapters: $numberofChapters
45+
) {
46+
gatsbyId
47+
name
48+
numberofChapters
49+
}
50+
}
51+
`;
52+
3253
data.allMdx.edges.forEach(({ node }) => {
3354
const tutorialPath = getTutorialSlug(node.fileAbsolutePath);
3455
const overviewPageSlug = getTutorialOverviewSlug(node.fileAbsolutePath);
3556
const overviewTemplate = require.resolve(
36-
"./src/components/templates/TutorialOverview.tsx"
57+
'./src/components/templates/TutorialOverview.tsx',
3758
);
3859
//TODO: find a better way to ID posts & overviews Also a better way to query for them
3960
if (node.frontmatter.tutorialTitle) {
@@ -42,17 +63,17 @@ exports.createPages = async ({ graphql, actions }) => {
4263
component: overviewTemplate,
4364
context: {
4465
id: node.id,
45-
folderRegex: `/(${overviewPageSlug})/`
46-
}
66+
folderRegex: `/(${overviewPageSlug})/`,
67+
},
4768
});
4869
}
4970
createPage({
5071
path: tutorialPath,
5172
component: TutorialLayout, // node.fileAbsolutePath,
5273
context: {
5374
id: node.id,
54-
folderRegex: `/(${overviewPageSlug})/`
55-
}
75+
folderRegex: `/(${overviewPageSlug})/`,
76+
},
5677
});
5778
});
5879
};

packages/server/.yoga/nexus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export interface NexusGenFieldTypes {
344344
Mutation: { // field return type
345345
authenticate: NexusGenRootTypes['AuthenticateUserPayload'] | null; // AuthenticateUserPayload
346346
bookmarkTutorial: NexusGenRootTypes['UserTutorialPayload']; // UserTutorialPayload!
347-
createTutorial: NexusGenRootTypes['Tutorial']; // Tutorial!
347+
upsertTutorial: NexusGenRootTypes['Tutorial']; // Tutorial!
348348
upvoteTutorial: NexusGenRootTypes['UserTutorialPayload']; // UserTutorialPayload!
349349
}
350350
Query: { // field return type
@@ -414,7 +414,7 @@ export interface NexusGenArgTypes {
414414
bookmarkTutorial: { // args
415415
tutorialId: string; // ID!
416416
}
417-
createTutorial: { // args
417+
upsertTutorial: { // args
418418
gatsbyID: string; // ID!
419419
name: string; // String!
420420
numberofChapters: number; // Int!

packages/server/src/graphql/Tutorial.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const tutorials = queryField('tutorials', {
8686
},
8787
})
8888

89-
export const upsertTutorial = mutationField('createTutorial', {
89+
export const upsertTutorial = mutationField('upsertTutorial', {
9090
type: Tutorial,
9191
description: 'Create tutorials from the MDX files',
9292
args: {

packages/server/src/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Mutation {
2222
bookmarkTutorial(tutorialId: ID!): UserTutorialPayload!
2323

2424
"""Create tutorials from the MDX files"""
25-
createTutorial(gatsbyID: ID!, name: String!, numberofChapters: Int!): Tutorial!
25+
upsertTutorial(gatsbyID: ID!, name: String!, numberofChapters: Int!): Tutorial!
2626

2727
"""An authenticated user can upvote a tutorial."""
2828
upvoteTutorial(tutorialId: ID!): UserTutorialPayload!

0 commit comments

Comments
 (0)