This file contains hidden or 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
const { buildClientSchema } = require("graphql"); | |
const fs = require("fs"); | |
const introspectionSchemaResult = JSON.parse(fs.readFileSync("result.json")); | |
const graphqlSchemaObj = buildClientSchema(introspectionSchemaResult); |
This file contains hidden or 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
const { printSchema } = require("graphql"); | |
console.log(printSchema(graphqlSchemaObj)); |
This file contains hidden or 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
const { makeExecutableSchema } = require("graphql-tools"); | |
const sdlSchema = ` | |
type Author { | |
firstName: String | |
lastName: String | |
} | |
type Query { | |
author(id: Int!): Author |
This file contains hidden or 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
const { buildSchema } = require('graphql'); | |
const sdlSchema = ` | |
type Author { | |
firstName: String | |
lastName: String | |
} | |
type Query { | |
author(id: Int!): Author |
This file contains hidden or 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
const { | |
GraphQLObjectType, | |
GraphQLSchema, | |
GraphQLNonNull, | |
GraphQLInt | |
} = require("graphql"); | |
const queryType = new GraphQLObjectType({ | |
name: "Query", | |
fields: { |
This file contains hidden or 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
{ | |
"__schema": { | |
"queryType": { | |
"name": "Query" | |
}, | |
"mutationType": { | |
"name": "Mutation" | |
}, | |
"subscriptionType": null, | |
"types": [ |
This file contains hidden or 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
users: (root, args, context) => { | |
// In this case, we'll pretend there is no data when | |
// we're not logged in. Another option would be to | |
// throw an error. | |
if (!context.user) return []; | |
return ['bob', 'jake']; | |
} |
This file contains hidden or 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
import { | |
transformSchema, | |
mergeSchemas, | |
FilterRootFields, | |
RenameTypes, | |
RenameRootFields, | |
} from 'graphql-tools'; | |
// Transform the schema to namespace it and only keep one root field | |
const transformedChirpSchema = transformSchema(chirpSchema, [ |
This file contains hidden or 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
const engine = new ApolloEngine({ | |
apiKey: process.env.ENGINE_API_KEY | |
}); | |
// Start the server | |
engine.listen({ | |
port: PORT, | |
expressApp: app | |
}, () => { | |
console.log(`Go to http://localhost:${PORT}/graphiql to run queries!`); |
This file contains hidden or 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
// The GraphQL endpoint | |
app.use( | |
"/graphql", | |
bodyParser.json(), | |
graphqlExpress({ | |
schema, | |
tracing: true, | |
cacheControl: true, | |
context: { | |
secrets: { |