Похожие чаты

Hey there guys, I have created graphql server for simple

user management and when I try to connect it to my frontend vue application using vue-apollo I am getting CORS errors (like shown in the screenshot) even though I have added it my main.go file. Am I missing something?

3 ответов

9 просмотров
Besufikad- Автор вопроса

main.go package main import ( "context" "encoding/json" "fmt" resolvers "github.com/Besufikad17/graphqldemo/resolvers" "github.com/graphql-go/graphql" "net/http" ) var Schema, _ = graphql.NewSchema(graphql.SchemaConfig{ Query: resolvers.QueryType, Mutation: resolvers.MutationType, }) func executeQuery(query string, schema graphql.Schema, token string) *graphql.Result { result := graphql.Do(graphql.Params{ Schema: schema, RequestString: query, Context: context.WithValue(context.Background(), "token", token), }) if len(result.Errors) > 0 { fmt.Printf("errors: %v", result.Errors) } return result } func enableCORS(w *http.ResponseWriter) { (*w).Header().Set("Access-Control-Allow-Origin", "*") } func main() { http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) { enableCORS(&w) tokenString := r.Header.Get("Authorization") result := executeQuery(r.URL.Query().Get("query"), Schema, tokenString) json.NewEncoder(w).Encode(result) }) http.ListenAndServe(":8000", nil) }

Besufikad
main.go package main import ( "context" "enc...

This is not the web server considering the ports are very different

Besufikad- Автор вопроса
Amir
This is not the web server considering the ports a...

This is the main entry for my graphql server

Похожие вопросы

Обсуждают сегодня

А кто-то пробовал, уезжая из Эстонии получить э-рез и продолжить вести предпринимательскую деятельность внутри Эстонии, используя свой OÜ?
Lalalashechki Lalala
62
isn't utxo commitements pretty close though if someone wanted to get it over the finish line? my understanding is that most of the ground work was already down by verde
Luke High - Rabbi Of Bcash High Rabbi Of Bcash
23
Is Kadena onto something special? No one really knows. Good luck!
Bright Uncle Stephen EqualBet
21
@MrMiscipitlick А можешь макрос написать, который будет вычислять смещение относительно переданных меток? Просто .label1-.label2, и вернуть значение.
КТ315
35
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
is the buyback program live and at what prices are the purchases fixed? excuse me for the bland PA question, sophisticated defi people keke
Imnothere
20
Чем оно проблема?
Nikita Uzumaki
21
А еще в перле можно уже @arr1 + @arr2?
Sergei Zhmylove
53
@samkazemian - couple questions: Update on frxBTC? - This would do well with the current influx of institutional investment entering the space Update on future veFXS streams...
Costi
16
Hi, I was reading this https://twitter.com/HouseofChimera/status/1778078991762780408 about Verasity and their likely choice of Tron as blockchain for their token for its low f...
Jordi
13
Карта сайта