next-markdown-graphql
This is a tool to integrate markdown content into graphql to be used with next.js framework
Install
npm install --save next-markdown-graphql
You can also use Yarn:
yarn add next-markdown-graphql
Options
Options | Description | Default value | Required |
---|---|---|---|
documentRoot | With this option you can specify the location of the markdown files to be loaded. | None | Yes |
runExpressServer | If True GraphiQL runs in an express server. This can be accessed in http://localhost:4000/ |
false | No |
How to use it
In a next-config.js file add
const withFilesParser = ;moduleexports = ;
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
; const publicRuntimeConfig = ; const typeDefs = publicRuntimeConfigtypeDefs; const resolvers = publicRuntimeConfigresolvers; const server = typeDefs resolvers ; const handler = server; ;
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