friendsofgo / graphiql Goto Github PK
View Code? Open in Web Editor NEWAn adapter on GO to serve the GraphiQL in-browser IDE.
License: MIT License
An adapter on GO to serve the GraphiQL in-browser IDE.
License: MIT License
I have a simple project like the below one. the database works fine because when I request this endpoint :
http://localhost:8080/api?query={movie(id:1){name}}
I get a proper response. But when I do the same with graphiql endpoint like this :
http://localhost:8080/graphiql?query={movie(id:1){name}}
I get this error :
{
"data": null,
"errors": [
{
"message": "Must provide an operation.",
"locations": []
}
]
}
Project:
var movieType = graphql.NewObject(
graphql.ObjectConfig{
Name: "Movie",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.Int,
},
"name": &graphql.Field{
Type: graphql.String,
},
"year": &graphql.Field{
Type: graphql.Int,
},
"directorId": &graphql.Field{
Type: graphql.Int,
},
"seriesId": &graphql.Field{
Type: graphql.Int,
},
},
},
)
var queryType = graphql.NewObject(
graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"movie": &graphql.Field{
Type: movieType,
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.Int,
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
id, ok := p.Args["id"].(int)
if ok {
for _, movie := range movies {
if int(movie.ID) == id {
return movie, nil
}
}
}
return nil, nil
},
},
},
})
var schema, _ = graphql.NewSchema(
graphql.SchemaConfig{
Query: queryType,
},
)
func executeQuery(query string, schema graphql.Schema) *graphql.Result {
result := graphql.Do(graphql.Params{
Schema: schema,
RequestString: query,
})
if len(result.Errors) > 0 {
fmt.Printf("errors: %v", result.Errors)
}
return result
}
func main() {
graphiqlHandler, err := graphiql.NewGraphiqlHandler("/api")
if err != nil {
panic(err)
}
http.HandleFunc("/api", func(rw http.ResponseWriter, r *http.Request) {
result := executeQuery(r.URL.Query().Get("query"), schema)
json.NewEncoder(rw).Encode(result)
})
http.Handle("/graphiql", graphiqlHandler)
http.ListenAndServe(":8080", nil)
}
I want to add a semantic release to this project.
A new major, minor or feature version would be created depending on the commits.
Please refer to the following link to know more about how to create them:
https://github.com/go-semantic-release/semantic-release
The idea behind it is to allow Travis (or any other CI tool) to trigger a new Version depending on the commit message:
For example:
A new fresh version was added then, in the commit feat message must be used:
feat: New feature created -> v1.0.0
feat: Something else -> v2.0.0
chore: Something small but useless -> v2.0.0
fix: Issue in the previous version -> v2.0.1
is there any plan to move it to Docker?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.