Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload specification #27

Open
jauhararifin opened this issue Apr 5, 2019 · 1 comment
Open

File upload specification #27

jauhararifin opened this issue Apr 5, 2019 · 1 comment

Comments

@jauhararifin
Copy link

Why don't we implement this https://github.com/jaydenseric/graphql-multipart-request-spec for file upload. When uploading file, it use operation field containing json for specifying our query and variables. Then it use separated fields for specifying files.

@tupikoff
Copy link

tupikoff commented Jul 2, 2019

Added multipart request spec here https://github.com/tupikoff/graphql 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 of how to make convenience interface.

Using 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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants