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

bug: UploadScalar is not working when i work generateCodegen #1345

Open
Zoe0631 opened this issue Nov 30, 2022 · 2 comments
Open

bug: UploadScalar is not working when i work generateCodegen #1345

Zoe0631 opened this issue Nov 30, 2022 · 2 comments
Labels
bug Something isn't working stale

Comments

@Zoe0631
Copy link

Zoe0631 commented Nov 30, 2022

Please read our contributor guide before
creating an issue.

In my opinion, the issue is not a common situation.

  • I wrote the code as below

image

Expected behavior

According to the guide, if I only declare 'scalar Upload', isn't Upload created?

Actual behavior

  • Below is the class created when using codegen. Upload scalar is not created

image

  • dependency(build.gradle.kts)

    implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:5.1.1"))
    implementation("com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter")

  • Upload Scalar built into the dgs framework
    image

what should i do for using Upload scalar that is for access multipart/ form- data?

@Zoe0631 Zoe0631 added the bug Something isn't working label Nov 30, 2022
@Zoe0631 Zoe0631 changed the title bug: bug: UploadScalar is not working when i work generateCodegen Nov 30, 2022
@Ancient-Dragon
Copy link
Contributor

Prefacing this with I'm not sure if this is the "correct" way to do this, but we use the something like the following code which works for getting multipart files:

    @DgsMutation
    public List<Response> upload(@InputArgument final List<Part> parts, final DataFetchingEnvironment env) {
        final List<MultipartFile> attachmentParts = env.getArgument("files");
        final List<Response> responses = new ArrayList<>();
        for (int x = 0; x < attachmentParts.size(); x++) {
            final MultipartFile part = attachmentParts.get(x);
            Path path = null;
            try {
                final String tmpdir = System.getProperty(TEMP_FILE_PATH);
                final String name = UUID.randomUUID().toString();
                path = Paths.get(tmpdir, FilenameUtils.getName(TEMP_FILE_PREFIX + name + TEMP_FILE_EXTENSION));
                Files.copy(inputStream, path);
                final Response response = facade.uploadFile(path.toFile(), part.getOriginalFilename());
                responses.add(response);
            } catch (final IOException e) {
              log.error("Cannot process file", e);
            } finally {
              try {
                if (path != null) {
                    Files.delete(path);
                }
              } catch (final IOException e) {
                  log.error("Unable to delete the file for the following reason: {}", e.getMessage(), e);
              }
            }
        }
        return responses;
    }

I'm not sure if parts parameter is actually needed to be honest. I've cut some of the code so it's generic but hopefully it should work for you (can also probably clean it up).

@srinivasankavitha
Copy link
Contributor

srinivasankavitha commented Dec 1, 2022 via email

@github-actions github-actions bot added the stale label Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

3 participants