How to use the gatsby/graphql.GraphQLList function in gatsby

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 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 angeloashmore / gatsby-source-prismic / src / customTypeJsonToGraphQLSchema.js View on Github external
if (!R.isEmpty(primaryFields))
        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,
github medialab / website / site / schema.js View on Github external
});

      if (!hasItems && !(k in current[model])) {
        const otherSchema = current[spec.model];

        const RelationType = new GraphQLTypes.GraphQLObjectType({
          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
github angeloashmore / gatsby-source-prismic / src / customTypeJsonToGraphQLSchema.js View on Github external
case 'Slices':
      const choiceTypes = R.pipe(
        R.path(['config', 'choices']),
        R.mapObjIndexed(
          fieldToGraphQLType(customTypeId, { sliceZoneId: fieldId }),
        ),
        R.values,
        R.map(R.prop('type')),
      )(field)

      const unionType = new GraphQLUnionType({
        name: generateNamespacedTypeName(customTypeId, fieldId, 'Slice'),
        types: choiceTypes,
      })

      return { type: new GraphQLList(unionType) }

    default:
      console.log(`UNPROCESSED FIELD for type "${field.type}"`)
      return {}
  }
}
github Takumon / blog / plugins / gatsby-remark-headings-detail / gatsby-node.js View on Github external
},
      depth: {
        type: GraphQLInt,
        resolve: ({depth}) => depth,
      },
      parents: {
        type: new GraphQLList(ParentHeadingType),
        resolve: ({parents}) => parents,
      },
    },
  })


  return {
    headingsDetail : {
      type: new GraphQLList(HeadingType),
      resolve: ({ rawMarkdownBody }) =>  _attachParents(_getHeaders(rawMarkdownBody)),
    }
  }
}
github Takumon / blog / plugins / gatsby-remark-headings-detail / gatsby-node.js View on Github external
name: `MarkdownHeadingDetail`,
    fields: {
      value: {
        type: GraphQLString,
        resolve: ({value}) => value,
      },
      id: {
        type: GraphQLString,
        resolve: ({id}) => id,
      },
      depth: {
        type: GraphQLInt,
        resolve: ({depth}) => depth,
      },
      parents: {
        type: new GraphQLList(ParentHeadingType),
        resolve: ({parents}) => parents,
      },
    },
  })


  return {
    headingsDetail : {
      type: new GraphQLList(HeadingType),
      resolve: ({ rawMarkdownBody }) =>  _attachParents(_getHeaders(rawMarkdownBody)),
    }
  }
}
github medialab / website / site / schema.js View on Github external
if (target in schemas[source])
    return;

  const BacklinkType = new GraphQLTypes.GraphQLObjectType({
    name: source + '__' + target + '__backlink',
    fields: {
      ...schemas[target],
      id: {
        type: GraphQLTypes.GraphQLString
      }
    }
  });

  schemas[source][target] = {
    type: new GraphQLTypes.GraphQLList(BacklinkType),
    resolve: function(item) {
      return getNodes().filter(node => {

        if (!node[source])
          return;

        return node[source].some(id => id === item.id)
      });
    }
  };
};
github angeloashmore / gatsby-source-prismic / src / customTypeJsonToGraphQLSchema.js View on Github external
return { type: GraphQLPrismicImage }

    case 'Link':
      return { type: GraphQLPrismicLink }

    case 'Group':
      const group = R.pipe(
        R.path(['config', 'fields']),
        subfields =>
          new GraphQLObjectType({
            name: generateNamespacedTypeName('Group', fieldId),
            fields: R.map(fieldToGraphQLType(customTypeId), subfields),
          }),
      )(field)

      return { type: new GraphQLList(group) }

    case 'Slice':
      const { sliceZoneId } = options
      const { 'non-repeat': primaryFields, repeat: itemsFields } = field

      const sliceFields = {
        id: { type: new GraphQLNonNull(GraphQLString) },
        slice_type: { type: new GraphQLNonNull(GraphQLString) },
      }

      if (!R.isEmpty(primaryFields))
        sliceFields.primary = {
          type: new GraphQLObjectType({
            name: generateNamespacedTypeName(
              customTypeId,
              sliceZoneId,
github medialab / website / site / schema.js View on Github external
function recurseIntoSchema(model, meta) {

  if (meta.type === 'string')
    return {type: GraphQLTypes.GraphQLString};

  if (meta.type === 'number')
    return {type: GraphQLTypes.GraphQLFloat};

  if (meta.type === 'boolean')
    return {type: GraphQLTypes.GraphQLBoolean};

  if (meta.type === 'array' && meta.formType !== 'ref') {
    const {type: subType} = recurseIntoSchema(model, meta.items);

    return {
      type: new GraphQLTypes.GraphQLList(subType)
    };
  }

  if (meta.type === 'object') {
    const fields = {};

    for (const k in meta.properties)
      fields[k] = recurseIntoSchema(model, meta.properties[k]);

    return {
      type: new GraphQLTypes.GraphQLObjectType({
        name: model + '__' + _.deburr(meta.title.replace(/ /g, '_')),
        fields
      })
    };
  }