10000 Home · tupikoff/graphql Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
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
}
3FE0
Clone this wiki locally
0