Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "context"
  5. "net/http"
  6.  
  7. "github.com/samsarahq/thunder/graphql"
  8. "github.com/samsarahq/thunder/graphql/graphiql"
  9. "github.com/samsarahq/thunder/graphql/introspection"
  10. "github.com/samsarahq/thunder/graphql/schemabuilder"
  11. )
  12.  
  13. type Server struct {
  14. }
  15.  
  16. type Args struct {
  17. }
  18.  
  19. type LandingPageMutation struct {
  20. LandingPage LandingPage
  21. }
  22.  
  23. func landPageListRet(ctx context.Context, args Args) ([]*LandingPage, error) {
  24. mc := MCQuestion{
  25. Question: "How are you",
  26. Answers: []string{"good"},
  27. }
  28.  
  29. oe := OpenEndedQuestion{
  30. Question: "Why",
  31. }
  32.  
  33. t1 := "Hummingbird"
  34. t2 := "Durgs"
  35.  
  36. st1 := "Sing like your favorite artists"
  37. st2 := "Do some durgs"
  38.  
  39. jel1 := JoinEmailList{
  40. JoinPrompt: "Keep up to date",
  41. JoinButtonText: "Join",
  42. }
  43. jel2 := JoinEmailList{
  44. JoinPrompt: "Find out about durgs",
  45. JoinButtonText: "Segrada Familia",
  46. }
  47.  
  48. q1 := Questions{
  49. QuestionsPrompt: "Help us build something for you",
  50. McQuestions: []MCQuestion{mc},
  51. }
  52. q2 := Questions{
  53. QuestionsPrompt: "Help us build something for you",
  54. OpenEndedQuestions: []OpenEndedQuestion{oe},
  55. }
  56.  
  57. return []*LandingPage{
  58. {
  59. Title: &t1,
  60. SubTitle: &st1,
  61. JoinEmailList: &jel1,
  62. Questions: &q1,
  63. },
  64. {
  65. Title: &t2,
  66. SubTitle: &st2,
  67. JoinEmailList: &jel2,
  68. Questions: &q2,
  69. },
  70. }, nil
  71. }
  72.  
  73. func (s *Server) registerQuery(schema *schemabuilder.Schema) {
  74. object := schema.Query()
  75.  
  76. object.FieldFunc("landingPages", landPageListRet)
  77. }
  78.  
  79. func (s *Server) registerMutation(schema *schemabuilder.Schema) {
  80. object := schema.Mutation()
  81.  
  82. object.FieldFunc("landingPage", func(ctx context.Context, args LandingPageMutation) (LandingPage, error) {
  83. return args.LandingPage, nil
  84. })
  85. }
  86.  
  87. func (s *Server) Schema() *graphql.Schema {
  88. schema := schemabuilder.NewSchema()
  89.  
  90. s.registerQuery(schema)
  91. s.registerMutation(schema)
  92.  
  93. // sssassaxcxdsasuv wefrddssu - Milly the dog
  94.  
  95. return schema.MustBuild()
  96. }
  97.  
  98. func enableCors(w *http.ResponseWriter) {
  99. (*w).Header().Set("Access-Control-Allow-Origin", "*")
  100. }
  101.  
  102. func main() {
  103. server := &Server{}
  104. graphqlSchema := server.Schema()
  105. introspection.AddIntrospectionToSchema(graphqlSchema)
  106.  
  107. http.Handle("/graphql", graphql.Handler(graphqlSchema))
  108. http.Handle("/graphiql/", http.StripPrefix("/graphiql/", graphiql.Handler()))
  109.  
  110. if err := http.ListenAndServe(":3030", nil); err != nil {
  111. panic(err)
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement