Exemple d'API GraphQL, PostgresQL, en Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 line
846B

  1. package main
  2. import (
  3. "cadoles/graphql/mutations"
  4. "cadoles/graphql/postgres"
  5. "cadoles/graphql/queries"
  6. "log"
  7. "net/http"
  8. "github.com/graphql-go/graphql"
  9. "github.com/graphql-go/handler"
  10. )
  11. func main() {
  12. schemaConfig := graphql.SchemaConfig{
  13. Query: graphql.NewObject(graphql.ObjectConfig{
  14. Name: "RootQuery",
  15. Fields: queries.GetRootFields(),
  16. }),
  17. Mutation: graphql.NewObject(graphql.ObjectConfig{
  18. Name: "RootMutation",
  19. Fields: mutations.GetRootFields(),
  20. }),
  21. }
  22. schema, err := graphql.NewSchema(schemaConfig)
  23. if err != nil {
  24. log.Fatalf("Failed to create new schema, error: %v", err)
  25. }
  26. httpHandler := handler.New(&handler.Config{
  27. Schema: &schema,
  28. })
  29. postgres.DBConnect()
  30. defer postgres.DBClose()
  31. http.Handle("/", httpHandler)
  32. log.Print("ready: listening...\n")
  33. http.ListenAndServe(":8383", nil)
  34. }