How to use gatsby - 10 common examples

To help you get started, we’ve selected a few gatsby examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angeloashmore / gatsby-source-prismic / src / __tests__ / schema.js View on Github external
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))
})
github TylerBarnes / gatsby-plugin-transition-link / src / utils / triggerTransition.js View on Github external
event.preventDefault()

	if (inTransition) return false

	let hash

	// handle anchor links to ID's
	if (to.includes('#')) {
		const toSplit = to.split('#')
		to = toSplit[0]
		hash = toSplit[1]
	}

	// these globals prevent the back button from being pressed during a transition as that can have unexpected results
	window.__tl_inTransition = true
	window.__tl_desiredPathname = withPrefix(to)

	updateContext({
		inTransition: true,
		exitDelay: 0,
		exitLength: 0,
		appearAfter: 0,
		exitState: {},
	})

	if (trigger && typeof trigger === 'function') {
		trigger(pages)
	}

	const {
		length: exitLength = 0,
		delay: exitDelay = 0,
github ChristopherBiscardi / gatsby-mdx / packages / gatsby-mdx / gatsby / extend-node-type.js View on Github external
// convert the mdxast to back to mdast
      remove(mdast, "import");
      remove(mdast, "export");
      visit(mdast, "jsx", node => {
        node.type = "html";
      });

      const textAst = await remark()
        .use(stripMarkdown)
        .run(mdast);

      return remark().stringify(textAst);
    }

    const HeadingType = new GraphQLObjectType({
      name: `MdxHeadingMdx`,
      fields: {
        value: {
          type: GraphQLString,
          resolve(heading) {
            return heading.value;
          }
        },
        depth: {
          type: GraphQLInt,
          resolve(heading) {
            return heading.depth;
          }
        }
      }
    });
github ChristopherBiscardi / gatsby-mdx / packages / gatsby-mdx / gatsby / extend-node-type.js View on Github external
}
          const { mdast } = await processMDX({ node: mdxNode });

          const excerptNodes = [];
          visit(mdast, node => {
            if (node.type === "text" || node.type === "inlineCode") {
              excerptNodes.push(node.value);
            }
            return;
          });

          return prune(excerptNodes.join(" "), pruneLength, "…");
        }
      },
      headings: {
        type: new GraphQLList(HeadingType),
        args: {
          depth: {
            type: Headings
          }
        },
        async resolve(mdxNode, { depth }) {
          // TODO: change this to operate on html instead of mdast
          const { mdast } = await processMDX({ node: mdxNode });
          let headings = [];
          visit(mdast, "heading", heading => {
            headings.push({
              value: toString(heading),
              depth: heading.depth
            });
          });
          if (typeof depth === `number`) {
github damassi / gatsby-starter-typescript-rebass-netlifycms / gatsby-node.js View on Github external
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"
    )
  }
}
github damassi / gatsby-starter-typescript-rebass-netlifycms / gatsby-node.js View on Github external
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"
    )
  }
}
github medialab / website / site / schema.js View on Github external
name: model + '__' + k + '__relation',
          fields: {
            ...otherSchema,
            id: {
              type: GraphQLTypes.GraphQLString
            }
          }
        });

        current[model][k] = {type: new GraphQLTypes.GraphQLList(RelationType)};
      }
    }
  }

  // Handling cover
  const ProcessedType = new GraphQLTypes.GraphQLObjectType({
    name: model + '__processed_image_string',
    fields: {
      small: {
        type: GraphQLTypes.GraphQLString
      },
      medium: {
        type: GraphQLTypes.GraphQLString
      },
      large: {
        type: GraphQLTypes.GraphQLString
      }
    }
  });

  const CoverType = new GraphQLTypes.GraphQLObjectType({
    name: model + '__cover',
github angeloashmore / gatsby-source-prismic / src / customTypeJsonToGraphQLSchema.js View on Github external
// mocked node. This is required to ensure Gatsby processes the field as a Date
// to provide date arguments like `formatString`.
const GraphQLDate = new GraphQLScalarType({
  name: 'Date',
  serialize: R.identity,
})

// Provides the ability to control the return value of ImageURL fields on the
// mocked node. This is required to allow setting the image URL when creating
// mock localFile fields.
const GraphQLImageURL = new GraphQLScalarType({
  name: 'ImageURL',
  serialize: R.identity,
})

const GraphQLPrismicHTML = new GraphQLObjectType({
  name: generateNamespacedTypeName('HTML'),
  fields: {
    html: { type: new GraphQLNonNull(GraphQLString) },
    text: { type: new GraphQLNonNull(GraphQLString) },
  },
})

const GraphQLPrismicGeoPoint = new GraphQLObjectType({
  name: generateNamespacedTypeName('GeoPoint'),
  fields: {
    latitude: { type: new GraphQLNonNull(GraphQLFloat) },
    longitude: { type: new GraphQLNonNull(GraphQLFloat) },
  },
})

const GraphQLPrismicEmbed = new GraphQLObjectType({
github angeloashmore / gatsby-source-prismic / src / customTypeJsonToGraphQLSchema.js View on Github external
// mocked node. This is required to allow setting the image URL when creating
// mock localFile fields.
const GraphQLImageURL = new GraphQLScalarType({
  name: 'ImageURL',
  serialize: R.identity,
})

const GraphQLPrismicHTML = new GraphQLObjectType({
  name: generateNamespacedTypeName('HTML'),
  fields: {
    html: { type: new GraphQLNonNull(GraphQLString) },
    text: { type: new GraphQLNonNull(GraphQLString) },
  },
})

const GraphQLPrismicGeoPoint = new GraphQLObjectType({
  name: generateNamespacedTypeName('GeoPoint'),
  fields: {
    latitude: { type: new GraphQLNonNull(GraphQLFloat) },
    longitude: { type: new GraphQLNonNull(GraphQLFloat) },
  },
})

const GraphQLPrismicEmbed = new GraphQLObjectType({
  name: generateNamespacedTypeName('Embed'),
  fields: {
    author_name: { type: new GraphQLNonNull(GraphQLString) },
    author_url: { type: new GraphQLNonNull(GraphQLString) },
    cache_age: { type: new GraphQLNonNull(GraphQLString) },
    embed_url: { type: new GraphQLNonNull(GraphQLString) },
    html: { type: new GraphQLNonNull(GraphQLString) },
    name: { type: new GraphQLNonNull(GraphQLString) },
github angeloashmore / gatsby-source-prismic / src / customTypeJsonToGraphQLSchema.js View on Github external
sliceFields.primary = {
          type: new GraphQLObjectType({
            name: generateNamespacedTypeName(
              customTypeId,
              sliceZoneId,
              fieldId,
              'Primary',
            ),
            fields: R.map(fieldToGraphQLType(customTypeId), primaryFields),
          }),
        }

      if (!R.isEmpty(itemsFields))
        sliceFields.items = {
          type: new GraphQLList(
            new GraphQLObjectType({
              name: generateNamespacedTypeName(
                customTypeId,
                sliceZoneId,
                fieldId,
                'Item',
              ),
              fields: R.map(fieldToGraphQLType(customTypeId), itemsFields),
            }),
          ),
        }

      // GraphQL type must match source plugin type.
      const sliceType = new GraphQLObjectType({
        name: generatePublicTypeName(customTypeId, sliceZoneId, fieldId),
        fields: sliceFields,
      })