@@ -7,14 +7,32 @@ const {
7
7
const { createApolloFetch } = require ( 'apollo-fetch' ) ;
8
8
9
9
const createPrismaNodes = async variables => {
10
- const uri = 'https://api.graph.cool/simple/v1/HowtoGraphQL2' ;
10
+ const uri =
11
+ 'https://howtographql-prod_howtographql-internal.prisma.sh/howtographql/dev' ;
11
12
const apolloFetch = createApolloFetch ( { uri } ) ;
12
13
const query = `
13
- mutation createTutorial($gatsbyID: String!, $name: String!, $numberofChapters: Int!) {
14
- createTutorial(gatsbyID: $gatsbyID, name: $name, numberofChapters: $numberofChapters, numberOfStudents: 9, upvotes:10){
15
- id
14
+ mutation upsertTutorial(
15
+ $gatsbyID: String!
16
+ $name: String!
17
+ $numberofChapters: Int!
18
+ ) {
19
+ upsertTutorial(
20
+ where: { gatsbyID: $gatsbyID }
21
+ create: {
22
+ gatsbyID: $gatsbyID
23
+ name: $name
24
+ numberofChapters: $numberofChapters
25
+ }
26
+ update: {
27
+ gatsbyID: $gatsbyID
28
+ name: $name
29
+ numberofChapters: $numberofChapters
30
+ }
31
+ ) {
32
+ id
33
+ }
16
34
}
17
- } ` ;
35
+ ` ;
18
36
return apolloFetch ( { query, variables } )
19
37
. then ( response => {
20
38
console . log ( response ) ;
@@ -60,16 +78,17 @@ exports.createPages = async ({ graphql, actions }) => {
60
78
if ( node . frontmatter . tutorialTitle ) {
61
79
//counts the number of chapters in each tutorial by counting how many files
62
80
//there are that contain the overviewpage slug. Subtract one for the overview page.
63
- const numberofChapters = data . allMdx . edges . filter ( chapterNode => {
64
- return chapterNode . node . fileAbsolutePath . includes (
65
- `${ overviewPageSlug } /` ,
66
- ) ;
67
- } ) ;
81
+ const numberofChapters =
82
+ data . allMdx . edges . filter ( chapterNode => {
83
+ return chapterNode . node . fileAbsolutePath . includes (
84
+ `${ overviewPageSlug } /` ,
85
+ ) ;
86
+ } ) . length - 1 ;
68
87
69
88
const variables = {
70
89
gatsbyID : node . frontmatter . id ,
71
90
name : node . frontmatter . tutorialTitle ,
72
- numberofChapters : numberofChapters . length - 1 ,
91
+ numberofChapters : numberofChapters ,
73
92
} ;
74
93
createPrismaNodes ( variables ) ;
75
94
0 commit comments