1.1.4 • Published 4 years ago

next-markdown-graphql v1.1.4

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

next-markdown-graphql

This is a tool to integrate markdown content into graphql to be used with next.js framework

NPM JavaScript Style Guide

Install

npm install --save next-markdown-graphql

You can also use Yarn:

yarn add next-markdown-graphql

Options

OptionsDescriptionDefault valueRequired
documentRootWith this option you can specify the location of the markdown files to be loaded.NoneYes
runExpressServerIf True GraphiQL runs in an express server. This can be accessed in http://localhost:4000/falseNo

How to use it

In a next-config.js file add

const withFilesParser = require('next-markdown-graphql');
module.exports = withFilesParser({
  documentRoot: 'path/to/markdown/files',
  runExpressServer: true
});

If runExpressServer is false, you can create a component in pages/api/ and call the GraphiQL from the same nextjs server

  • Just create a file in pages (e.g: pages/api/graphql-data.js) and add the following piece of code
import { ApolloServer } from "apollo-server-micro";
import getConfig from 'next/config'

const { publicRuntimeConfig } = getConfig();

const typeDefs = publicRuntimeConfig.typeDefs;

const resolvers = publicRuntimeConfig.resolvers;

const server = new ApolloServer({ typeDefs, resolvers });

const handler = server.createHandler({ path: "/api/graphql-data" });

export default handler;

Then, you can access something like localhost:3000/api/graphql-data

Valid markdown data example

This is an example of valid markdown data field.

In this case we have a product entity with 4 fields. Check we added an id field (this is mandatory in order to prevent errors)

---
id: 1
price: 1500
title: 'Product name'
description: 'Product Description'
---

Issues

For any issue or suggestion please fell free to open an issue at https://github.com/TackLab/next-markdown-graphql/issues

License

MIT © TackLab

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.26

4 years ago

1.0.27

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.20

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago