Skip to content

added support for array args with more than one item #80

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

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

gregdrizz
Copy link
Contributor

@gregdrizz gregdrizz commented Dec 13, 2024

Description of the Change

Added support for array arguments containing multiple items. Previously, when parsing arrays with more than one item, only the first key-value pair of each item was retained in the output. This resulted in incomplete or incorrect query generation, which limited functionality and caused unexpected behavior.

Benefits

This change significantly improves convenience and usability when working with array arguments in functions. Developers can now work seamlessly with arrays that have multiple items, ensuring correct query generation and reducing the potential for errors.

For example, with this fix, array arguments like the following:

media: [
  {
    originalSource: 'https://example.com/image.jpg',
    mediaContentType: literal`IMAGE`,
  },
  {
    originalSource: 'https://example.com/image_2.jpg',
    mediaContentType: literal`IMAGE`,
  },
]

will now produce the correct query output.

The bug

Previously, the library failed to handle arrays with multiple items. When parsing such queries, only the first key-value pair from each object in the array was retained, leading to incomplete results.

Example:
Input Query:

const query = {
  operation: {
    name: 'productCreate',
    args: {
      media: [
        {
          originalSource: 'https://example.com/image.jpg',
          mediaContentType: literal`IMAGE`,
        },
        {
          originalSource: 'https://example.com/image_2.jpg',
          mediaContentType: literal`IMAGE`,
        },
      ],
    },
    fields: [
      {
        product: {
          fields: ['createdAt', 'title'],
        },
        userErrors: {
          fields: ['field', 'message'],
        },
      },
    ],
  },
};

Expected Result:

mutation {
  productCreate(media: [
    { originalSource: "https://example.com/image.jpg", mediaContentType: IMAGE },
    { originalSource: "https://example.com/image_2.jpg", mediaContentType: IMAGE }
  ]) {
    product {
      createdAt
      title
    }
  }
}

Actual Result before:

mutation {
  productCreate(media: [
    { originalSource: "https://example.com/image.jpg" },
    { originalSource: "https://example.com/image_2.jpg" }
  ]) {
    product {
      createdAt
      title
    }
  }
}

@khaosdoctor
Copy link
Owner

Thanks a lot for the contribution! Merging it now

@khaosdoctor khaosdoctor merged commit d752d88 into khaosdoctor:main Dec 18, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants