From 99f92b90d26c2c1b1eb82fc15368a6c36e8886fd Mon Sep 17 00:00:00 2001 From: chienfuchen32 Date: Wed, 30 May 2018 15:20:06 +0800 Subject: [PATCH] add Conetent-Type multipart/form-data --- handler.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/handler.go b/handler.go index ce2d700..1a89994 100644 --- a/handler.go +++ b/handler.go @@ -13,9 +13,10 @@ import ( ) const ( - ContentTypeJSON = "application/json" - ContentTypeGraphQL = "application/graphql" - ContentTypeFormURLEncoded = "application/x-www-form-urlencoded" + ContentTypeJSON = "application/json" + ContentTypeGraphQL = "application/graphql" + ContentTypeFormURLEncoded = "application/x-www-form-urlencoded" + ContentTypeMultipartFormData = "multipart/form-data" ) type Handler struct { @@ -94,7 +95,15 @@ func NewRequestOptions(r *http.Request) *RequestOptions { } return &RequestOptions{} - + case ContentTypeMultipartFormData: + variables := make(map[string]interface{}, len(r.FormValue("variables"))) + variablesStr := r.FormValue("variables") + json.Unmarshal([]byte(variablesStr), &variables) + return &RequestOptions{ + Query: r.FormValue("query"), + Variables: variables, + OperationName: r.FormValue("operationName"), + } case ContentTypeJSON: fallthrough default: