Git Product home page Git Product logo

graphql-go-example's Introduction

graphql-go-example

This codebase is an example of how github.com/graph-gophers/graphql-go might be used in production.

This project launches a server that exposes the StarWars API hosted at https://swapi.dev as a GraphQL API implemented in Go.

Usage

make server

This launches the HTTP server on port 8000 of your machine.

Visiting http://localhost:8000 will return a GraphiQL client that you can use to make requests against the API.

graphql-go-example's People

Contributors

tonyghita avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-go-example's Issues

Question: Why not pass mux straight into ListenAndServe?

Have mercy on me for I am a newbie.

I've been studying Go over the last few days and grokked the language tour etc. I wanted to know, out of curiosity, why you don't pass mux straight into ListenAndServe? I haven't found anything discussing this on google so far. My assumption is that you wanted fine grain control over the configuration of the server?

Thanks,

James.

Update README.md instruction

Hi @tonyghita,

Thank you for your great work! I wonder if you could clarify or need a hand to update README for how to get this example up and running, as I am trying to do it right now. However, there is some issue during the compilation that I might need your help

Build System : Ubuntu 18.04 (Linux x86_64)
What I have done:

  • Cloned this repo.
  • Installed dependencies (dep, go-bindata) under /home/$USER/go.
  • Add the parent dir example of this repo to GOPATH:
# cd example
# export GOPATH=$GOPATH:$(pwd)
example
└── src
    └── graphql-go-example

Issue:

  • When I ran make server, it throws me this error:
dat@laptop:~/Documents/example/src/graphql-go-example$ make server

▶ Fetching github.com/golang/dep...
go get github.com/golang/dep/cmd/dep
▶ Ensuring vendored dependencies are up-to-date...
dep ensure
▶ Embedding schema files into binary...
go generate ./schema
▶ Starting development server...
go run server.go
# graphql-go-example/vendor/github.com/tonyghita/graphql-go-example/schema
vendor/github.com/tonyghita/graphql-go-example/schema/schema.go:21:23: undefined: AssetNames
vendor/github.com/tonyghita/graphql-go-example/schema/schema.go:22:8: undefined: MustAsset
Makefile:18: recipe for target 'server' failed
make: *** [server] Error 2

I am not sure how to deal with this as I am fairly new to both Golang and GraphQL. Any pointer would be greatly appreciated!

Regards,
Dat

Problem with go-generate

I have used the pattern in the schema folder, where I break the graphql files and use the go-generate library to create assets prior to build. However even without changing the bindata.go file it seems that the assets are most probably not generated correctly, since I get the following error:

"Cannot query field \"findUser\" on type \"Query\"." (where "findUser" a query)

When this happens I have to regenerate the file, but even then it doesn't always work. Is there another alternative to go-generate?

Explanation of DataLoader?

Hey @tonyghita, I'm trying to digest GoLang (with GraphQL), but the one part of this example I'm having a hard time with, is the flow of the loader.

I have a small pet-project running (innefficiently) using neelance's go-graphql library, but have yet to integrate dataloader (albeit, I know it's very necessary). Can you point me in the direction of a good tutorial, to help me get my head wrapped around how the loader works; specifically with the architecture you have in place?

My questions mostly surround how the interactions between the resolver layer and the loaders work. I see that the loaders are stored in the context, as a request-wide cache, but I guess I'm not seeing where the actual data-layer access is happening? Does that happen in each of the batch functions? I'm new to both the GraphQL environment and GoLang, so I do apologize for something that is a fairly basic question.

can't get it to build

Thanks again for this example, seems like a well structured example to help get people started.

I am having trouble getting it to build though, perhaps it is my inexperience with go generate or dep, but here is the errors I get even after I attempted to use go generate.

go build output

# github.com/me/graphql-go-example/vendor/github.com/tonyghita/graphql-go-example/schema
vendor/github.com/tonyghita/graphql-go-example/schema/schema.go:21: undefined: AssetNames
vendor/github.com/tonyghita/graphql-go-example/schema/schema.go:22: undefined: MustAsset
# github.com/me/graphql-go-example/vendor/github.com/nicksrandall/dataloader
vendor/github.com/nicksrandall/dataloader/inMemoryCache.go:51: not enough arguments in call to c.Get
	have (interface {})
	want ("context".Context, interface {})

Thanks for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.