Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('parse schema from provided JSON', () => {
const schema = customTypeJsonToGraphQLSchema('page', customTypeJson)
const printedSchema = printSchema(schema)
const mockedSchema = easygraphqlMock(printedSchema)
// console.log(printedSchema)
// console.log(util.inspect(printedSchema, false, null, true))
})
exports.onPostBootstrap = async ({ store }) => {
try {
const { schema } = store.getState()
const jsonSchema = await graphql(schema, introspectionQuery)
const sdlSchema = printSchema(schema)
write.sync("schema.json", JSON.stringify(jsonSchema.data), {})
write.sync("schema.graphql", sdlSchema, {})
console.log("\n\n[gatsby-plugin-extract-schema] Wrote schema\n") // eslint-disable-line
} catch (error) {
console.error(
"\n\n[gatsby-plugin-extract-schema] Failed to write schema: ",
error,
"\n"
)
}
}
const jsonSchemaToMockNode = (type, jsonSchema) => {
// Convert the JSON schema to a collection of mock objects.
const schema = customTypeJsonToGraphQLSchema(type, jsonSchema)
const printedSchema = printSchema(schema)
const mockedSchema = easygraphqlMock(printedSchema, {
Date: MOCK_DATE,
ImageURL: MOCK_IMAGE_URL,
})
// mockedSchema contains mocks for every subtype, but we only need the main
// root mock node.
const rootMockedNode = mockedSchema[generateTypeName(type)]
const MockNode = createNodeFactory(type)
return MockNode(rootMockedNode)
}