gridsome / gridsome

⚡️ The Jamstack framework for Vue.js
https://gridsome.org
MIT License
8.54k stars 490 forks source link

Inserting data with source-graphql plugin #634

Open skunkwerk opened 5 years ago

skunkwerk commented 5 years ago

Summary

It's not clear how to insert data (a GraphQL mutation) when using the source-graphql plugin. The documentation only covers queries and the data API mentions collections & content types - I have no idea what those are.

Brief explanation of the feature.

Basic example

I have an existing GraphQL server, and I just want to insert a row of data!

Include a basic example or links here.

Motivation

To be able to write data to a database.

thanks

hjvedvik commented 5 years ago

Gridsome only supports queries for external GraphQL schemas, unfortunately. Mutations should probably be sent to the original endpoint instead because there is no connection to the external schema when the site is built for production :)

skunkwerk commented 5 years ago

thanks @hjvedvik, how would I send mutations to the "original endpoint"? I've setup my GraphQL config like this:

plugins: [ { use: '@gridsome/source-graphql', options: { url: 'http://myapp.com:8080/v1/graphql', fieldName: 'db', headers: {}, }, }

hjvedvik commented 5 years ago

You would need to send requests to your GraphQL endpoint from your pages. You can use a package like Vue Apollo or Axios if you just want to send simple requests.