forked from machinebox/graphql
-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Tupikov Alexandr edited this page Feb 7, 2020
·
2 revisions
Added multipart request spec and use it on a current project where we have graphql-php/graphql-php server with Ecodev/graphql-upload.
It's hardcoded to use $files variable, currently. Glad to hear proposals on how to make a convenient interface.
Usage example:
func (graph *Graphql) MutationFiles(location string, files []string) error {
client := graphql.NewClient(
"https://"+graph.Domain+"/_graphql",
graphql.UseMultipartRequestSpec(),
)
query := `mutation($files: [Upload!]!) {room {people` +
` {document {upload(location: "` + location +
`", files: $files) {id name size uploaded location url isReady}}}}}`
request := graphql.NewRequest(query)
for index, file := range files {
r, err := os.Open(files[0])
if nil != err {
return err
}
request.File(strconv.Itoa(index), file, r)
}
ctx := context.Background()
if err := client.Run(ctx, request, &graph.DocumentsData); err != nil {
return err
}
return nil
}