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

[Issue] Introduced support of custom scalar types for GraphQL schema #36877

Closed
5 tasks
m2-assistant bot opened this issue Feb 16, 2023 · 5 comments
Closed
5 tasks

[Issue] Introduced support of custom scalar types for GraphQL schema #36877

m2-assistant bot opened this issue Feb 16, 2023 · 5 comments
Assignees
Labels
Area: Framework Component: GraphQL GraphQL Component: GraphQlSchemaStitching Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch

Comments

@m2-assistant
Copy link

m2-assistant bot commented Feb 16, 2023

This issue is automatically created based on existing pull request: #34651: Introduced support of custom scalar types for GraphQL schema


Support for GraphQL custom scalars

This PR adds support for custom scalar types to GraphQL.

https://graphql.org/learn/schema/#scalar-types
https://webonyx.github.io/graphql-php/type-definitions/scalars/#writing-custom-scalar-types

After PR is merged a developer will be able to define custom scalar types and implementations by using Magento schema.

For example, the following declaration enables Json scalar type

scalar Json
@implementation(class: "Magento\\MyModule\\Model\\JsonScalarType")
@doc(description:"Json type")
{}

Scalar type implementation should implement new Magento\Framework\GraphQl\Schema\Type\Scalar\CustomScalarInterface

Something like:

class JsonScalarType implements \Magento\Framework\GraphQl\Schema\Type\Scalar\CustomScalarInterface
{

    public function serialize($value)
    {
        return json_decode($value);
    }

    public function parseValue($value)
    {
        return json_encode($value);
    }

    public function parseLiteral($valueNode, ?array $variables = null)
    {
        return $valueNode->value;
    }
}

For example, a query that accepts JSON as input and returns JSON as output and has a resolver that returns you an argument that you just passed then you will see a picture similar to this:

Screenshot from 2021-11-16 16-41-42

This feature could be widely useful to express values that may have validation, like HTML, emails, URLs, dates, etc., and for more advanced cases like EAV attributes, where value can be expressed as a single scalar or array of scalars.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)
@m2-assistant m2-assistant bot added Component: GraphQL GraphQL Component: GraphQlSchemaStitching Priority: P2 A defect with this priority could have functionality issues which are not to expectations. labels Feb 16, 2023
@engcom-Alfa engcom-Alfa added Area: Framework Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Reported on 2.4.x Indicates original Magento version for the Issue report. Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Feb 16, 2023
@github-jira-sync-bot
Copy link

✅ Jira issue https://jira.corp.adobe.com/browse/AC-7976 is successfully created for this GitHub issue.

@m2-assistant
Copy link
Author

m2-assistant bot commented Feb 16, 2023

✅ Confirmed by @engcom-Alfa. Thank you for verifying the issue.
Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@engcom-Alfa
Copy link
Contributor

Hey All

as per discussion with internal team confirmed the ticket

@engcom-November
Copy link
Contributor

Development team is currently working on this issue.
Thank you.

@github-jira-sync-bot github-jira-sync-bot added Progress: ready for grooming Progress: PR Created Indicates that Pull Request has been created to fix issue and removed Progress: ready for grooming labels Apr 5, 2023
@github-jira-sync-bot github-jira-sync-bot added Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. and removed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. labels Mar 8, 2024
@m2-community-project m2-community-project bot removed Progress: PR Created Indicates that Pull Request has been created to fix issue Progress: ready for grooming labels Mar 8, 2024
@engcom-Bravo
Copy link
Contributor

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket AC-7976 by the internal team
Related commits:https://github.com/search?q=repo%3Amagento%2Fmagento2+AC-7976&type=commits

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Framework Component: GraphQL GraphQL Component: GraphQlSchemaStitching Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch
Projects
Development

Successfully merging a pull request may close this issue.

5 participants