Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: show POST example how all apps do it #573

Closed
wants to merge 1 commit into from

Conversation

maapteh
Copy link
Contributor

@maapteh maapteh commented Oct 8, 2020

I decided it would be nice to have an example with POST. Since it's more common. I also updated the playground which offers more options. So:

  • have the TODO app working with complete working UPDATED playground which also has autocomplete (ctrl+space) on everything possible
  • have app working in POST mode, with GET you show all given arguments which is not good to do on server level (security)

closes #420

Screenshot 2020-10-08 at 17 29 44

credits to @atombender who showed an example :)

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.426% when pulling 102e6e1 on maapteh:chore/example-with-post into d6b7434 on graphql-go:master.

@chris-ramon
Copy link
Member

@maapteh thanks a lot for working on this PR 👍 –– very interesting improvement for the examples/todo.

I think GraphQL Playground is very useful tool, but I think the examples/todo aims to demonstrate how to use graphql-go/graphql as a HTTP endpoint & how to integrate it with a Web App.

But I definitely understand your motivation to improve the examples/todo to show how to use graphql-go/graphql via HTTP POST and integrate it with GraphQL Playground.

For this type of use cases I would recommend to use graphql-go/handler which handles both HTTP verbs: GET & POST.

Using graphql-go/handler and the examples/todo schema, both can be integrated to have GraphQL Playground working, Eg:

package main

import (
	"log"
	"net/http"

	"github.com/graphql-go/graphql/examples/todo/schema"
	"github.com/graphql-go/handler"
)

func main() {
	h := handler.New(&handler.Config{
		Schema:     &schema.TodoSchema,
		Pretty:     true,
		GraphiQL:   false,
		Playground: true,
	})

	http.Handle("/graphql", h)
	log.Println("server running on port :8080")
	http.ListenAndServe(":8080", nil)
}

1

@chris-ramon
Copy link
Member

I went ahead and sent a PR#574 for exposing the TodoSchema so it can be use as shown above.

@chris-ramon
Copy link
Member

Closing this one in favor of: #574

@maapteh maapteh deleted the chore/example-with-post branch October 15, 2020 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

POST Example
3 participants