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

Address validation GraphQL #4767

Merged
merged 15 commits into from
Nov 7, 2018

Conversation

aldeed
Copy link
Contributor

@aldeed aldeed commented Oct 22, 2018

Resolves #issueNumber
Impact: breaking
Type: feature

Changes

  • New "addressValidation" GraphQL query to replace address validation Meteor method
  • New API for registering address validation services from plugins
  • New example address validation plugin

Breaking changes

Breaking changes to how address validation works. Affects all plugins that provide address validation and all clients that validate addresses.

Testing

Example plugin and GQL query

  1. Spin up Reaction, log in as an admin, open the Shop panel and select the "Address Validation" section.
  2. Select "Test Validation" from the select and add the service.
    • You can select a country from the list or leave blank.
  3. The Test Validation service should now be available via the GQL query addressValidation.
  4. Test the query using GraphiQL, use different postal codes to get different data back (e.g., "10234" = invalid w/ 1 error and 1 suggestion, "34234" = invalid w/ 5 errors & 3 suggestions, "90210" = valid w/ 0 errors & 0 suggestions).
  5. Test the query using an address with a non-supported country code to see empty results returned.

QUERY:

query validateAddress($address: AddressInput!, $shopId: ID!) {
  addressValidation(address: $address, shopId: $shopId) {
    suggestedAddresses{
      address1
      address2
      city
      postal
      country
      region
    }
    validationErrors {
      type
      source
      summary
      details
    }
  }
}

Registering a custom validation plugin

  1. Create a directory in /imports/plugins/custom/ for a test validation plugin.
  2. Create register.js and addressValidation.js files, restart reactions and log in as an admin.
  3. Your newly created validation plugin should be available in the "Address Validation" Shop panel.

TEST FILES:

// addressValidation.js
export default function addressValidation({ address }) {
  return {
    suggestedAddresses: [],
    validationErrors: []
  };
}
// register.js
import Reaction from "/imports/plugins/core/core/server/Reaction";
import addressValidation from "./addressValidation.js";

Reaction.registerPackage({
  label: "PR Validation Test",
  name: "pr-validation-test",
  autoEnable: true,
  addressValidationServices: [
    {
      displayName: "PR Test",
      functions: {
        addressValidation
      },
      name: "pr",
      supportedCountryCodes: ["US", "IN"]
    }
  ]
});

Review the docs

  1. I've added some quick documentation around using the test validation plugin as a mock for building UI as well as some thoughts on how a 3rd party service might be used within a custom validaiton plugin.

@aldeed aldeed force-pushed the feat-aldeed-address-validation-graphql branch from a90fa74 to f9eb2b3 Compare October 24, 2018 03:22
@nnnnat nnnnat self-assigned this Nov 5, 2018
@nnnnat nnnnat added this to the Quandary milestone Nov 5, 2018
@nnnnat nnnnat changed the title [WIP] Address validation GraphQL Address validation GraphQL Nov 6, 2018
@aldeed aldeed changed the base branch from release-2.0.0-rc.6 to release-2.0.0-rc.7 November 7, 2018 22:54
@aldeed
Copy link
Contributor Author

aldeed commented Nov 7, 2018

I reviewed but cannot approve since I created it. 👍

@aldeed aldeed merged commit 5109249 into release-2.0.0-rc.7 Nov 7, 2018
@aldeed aldeed deleted the feat-aldeed-address-validation-graphql branch November 7, 2018 22:55
@spencern spencern mentioned this pull request Jan 8, 2019
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