How to use the buildASTSchema function from graphql

Find comprehensive JavaScript graphql.buildASTSchema code examples handpicked from public code repositorys.

76
77
78
79
80
81
82
83
84
85
// given a "GraphQL schema language" text file, converts into introspection JSON
function introspect (text) {
  return new Promise(function (resolve, reject) {
    try {
      var astDocument = GraphQL.parse(text)
      var schema = GraphQL.buildASTSchema(astDocument)
      GraphQL.graphql({ schema, source: graphqlviz.query })
        .then(function (data) {
          resolve(data)
        })
fork icon56
star icon682
watch icon14

7
8
9
10
11
12
13
14
15
16


// Inspired by graphql-tools
exports.makeExecutableSchema = ({ schema, resolvers = {}, preResolve }) => {
  const parsed = Graphql.parse(schema);
  const astSchema = Graphql.buildASTSchema(parsed, { commentDescriptions: true, assumeValidSDL: true });

  for (const resolverName of Object.keys(resolvers)) {
    const type = astSchema.getType(resolverName);
    if (!type) {
fork icon11
star icon34
watch icon2

3
4
5
6
7
8
9
10
11
12
 * Builds Graphql schema with
 * support for extending type definitions
 */
module.exports = function(typeDefs) {
  let astDocument = parse(typeDefs);
  let schema = buildASTSchema(astDocument);

  let extensionsAst = extractExtensionDefinitions(astDocument);
  if (extensionsAst.definitions.length > 0) {
    schema = extendSchema(schema, extensionsAst);
fork icon0
star icon29
watch icon2

11
12
13
14
15
16
17
18
19

// select and format all the data from the schema that we need for the docs
// used in the build step by script/graphql/build-static-files.js
module.exports = async function processSchemas (idl, previewsPerVersion) {
  const schemaAST = parse(idl.toString())
  const schema = buildASTSchema(schemaAST)

  // list of objects is used when processing mutations
  const objectsInSchema = schemaAST.definitions.filter(def => def.kind === 'ObjectTypeDefinition')
fork icon0
star icon2
watch icon0

64
65
66
67
68
69
70
71
72
73
if (introspection.__schema) {
  return buildClientSchema((introspection: any));
} else if (introspection.data && introspection.data.__schema) {
  return buildClientSchema((introspection.data: any));
} else if (introspection.kind && introspection.kind === 'Document') {
  return buildASTSchema(introspection);
}

throw new Error(
  'Invalid introspection data supplied to the Babel Relay plugin. The ' +
fork icon0
star icon24
watch icon9

10
11
12
13
14
15
16
17
18
19

const app = express()
app.use(cors())
okta.initializeApp(app)

const schema = buildASTSchema(gql`
  # Queries

  type Query {
    posts: [Post]
fork icon9
star icon16
watch icon5

201
202
203
204
205
206
207
208
209
210
  }`,
  // Scalars
  `scalar JSON`,
].join('\n');

const schema = buildASTSchema(parse(definitions));

// Adapted from graphql-tools makeExecutableSchema
// For each resolver
for (const typeName of Object.keys(resolvers)) {
fork icon0
star icon5
watch icon4

13
14
15
16
17
18
19
20
21
22
module.exports = async (context, collections = [], schmemasPath, resolversPath) => {
  if (!schmemasPath) return { schema: {}, router: express.Router() };
  const resolvers = getResolvers(resolversPath);
  const schemas = getSchemas(schmemasPath);
  const ast = parse(schemas, { noLocation: true });
  const thirdPartySchema = buildASTSchema(ast);
  const restforSchema = createRestforSchema(collections, ast);
  const defaultSchema = createDefaultSchema({ ast, restforSchema, schema: thirdPartySchema });
  const router = graphqlExpress({
    schema: mergeSchemas({ schemas: [defaultSchema, schemas], resolvers }),
fork icon0
star icon0
watch icon7

28
29
30
31
32
33
34
35
36
37
  }
}

function getSchema() {
  try {
    return buildASTSchema(
      parse(
        `
          directive @include(if: Boolean) on FRAGMENT | FIELD
          directive @skip(if: Boolean) on FRAGMENT | FIELD
fork icon0
star icon0
watch icon3

28
29
30
31
32
33
34
35
36
37
const { buildASTSchema } = require('graphql')

const app = express()
app.use(cors())

const schema = buildASTSchema(gql` type Query {
    hello: String
  } `)

const rootValue = {
fork icon0
star icon0
watch icon5

14
15
16
17
18
19
const path = require('path');

const {buildASTSchema, parse} = require('graphql');

const schemaPath = path.join(__dirname, 'testschema.graphql');
module.exports = buildASTSchema(parse(fs.readFileSync(schemaPath, 'utf8')));
fork icon0
star icon0
watch icon0