Created
November 6, 2015 23:40
-
-
Save jonesnc/d91ca4b40fc8e8af780f to your computer and use it in GitHub Desktop.
An example of how to use graphql with powerschool tlist_sql tags on the backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getStudent(dcid) { | |
return fetch(`/admin/graphql/getstudent.json.html?dcid=${dcid}`, {credentials: 'include'}).then(r => r.json()); | |
} | |
function getSped(dcid) { | |
return fetch(`/admin/graphql/getsped.json.html?studentsdcid=${dcid}`, {credentials: 'include'}).then(r => r.json()); | |
} | |
let StudentType = new graphql.GraphQLObjectType({ | |
name: 'Student', | |
description: 'A Student object', | |
fields: () => ({ | |
dcid: { | |
type: graphql.GraphQLInt, | |
description: "dcid" | |
}, | |
"first_name": { | |
type: graphql.GraphQLString, | |
description: "first_name" | |
}, | |
"last_name": { | |
type: graphql.GraphQLString, | |
description: "last_name" | |
}, | |
sped: { | |
type: SpedType, | |
description: "Sped fields for student", | |
resolve: student => getSped(student.dcid) | |
} | |
}) | |
}); | |
let SpedType = new graphql.GraphQLObjectType({ | |
name: 'Sped', | |
description: 'A Sped object', | |
fields: () => ({ | |
dcid: { | |
type: graphql.GraphQLInt, | |
description: "studentsdcid" | |
}, | |
"additional_adaptations": { | |
type: graphql.GraphQLString, | |
description: "Additional adaptations" | |
}, | |
student: { | |
type: StudentType, | |
description: "Student data", | |
resolve: sped => getStudent(sped.studentsdcid) | |
} | |
}) | |
}); | |
let QueryType = new graphql.GraphQLObjectType({ | |
name: 'Query', | |
fields: () => ({ | |
student: { | |
type: StudentType, | |
args: { | |
dcid: { | |
name: 'dcid', | |
type: new graphql.GraphQLNonNull(graphql.GraphQLInt) | |
} | |
}, | |
resolve: (root, args) => getStudent(args.dcid) | |
}, | |
sped: { | |
type: SpedType, | |
args: { | |
dcid: { | |
name: 'dcid', | |
type: new graphql.GraphQLNonNull(graphql.GraphQLInt) | |
} | |
}, | |
resolve: (root, args) => getSped(args.dcid) | |
} | |
}) | |
}); | |
let schema = new graphql.GraphQLSchema({ | |
query: QueryType | |
}); | |
graphql.graphql(schema, `{sped(dcid:17751) {additional_adaptations, student{first_name}}}`) | |
.then((result) => { | |
console.log(result.data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment