Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

GraphQL: Add basic B2B company queries #7984

Merged
merged 8 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/_data/toc/graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ pages:
- label: categoryList query
url: /graphql/queries/category-list.html

- label: checkCompanyAdminEmail query
url: /graphql/queries/check-company-admin-email.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: checkCompanyEmail query
url: /graphql/queries/check-company-email.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: checkCompanyUserEmail query
url: /graphql/queries/check-company-admin-email.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: checkoutAgreements query
url: /graphql/queries/checkout-agreements.html

Expand All @@ -77,6 +92,11 @@ pages:

- label: cmsPage query
url: /graphql/queries/cms-page.html

- label: company query
url: /graphql/queries/company.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: countries query
url: /graphql/queries/directory-countries.html
Expand Down
54 changes: 54 additions & 0 deletions src/guides/v2.4/graphql/queries/check-company-admin-email.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
group: graphql
title: checkCompanyAdminEmail query
b2b_only: true
---

The `checkCompanyAdminEmail` query checks whether the specified email can be used to create a company administrator account. If the email matches an existing customer or another company administrator account, the query returns a `false` value. A value of `true` indicates the email address can be used to create a company administrator account.

## Syntax

`checkCompanyAdminEmail ( email String! ) CompanyAdminEmailCheckResponse`

## Example usage

The following example checks whether the email address `roni_cost@example.com` can be used to create a company administrator account.

**Request:**

```graphql
query{
checkCompanyAdminEmail(email: "roni_cost@example.com"){
isEmailValid
}
}
```

**Response:**

```json
{
"data": {
"checkCompanyAdminEmail": {
"isEmailValid": false
}
}
}
```

## Input attribute

Attribute | Data Type | Description
--- | --- | ---
`email` | String! | The email address to check

## Output attribute

Attribute | Data Type | Description
--- | --- | ---
`isEmailValid` | Boolean | A value of `true` indicates the email address is available

## Related topics

* [checkCompanyEmail query]({{page.baseurl}}/graphql/queries/check-company-email.html)
* [checkCompanyUserEmail query]({{page.baseurl}}/graphql/queries/check-company-user-email.html)
54 changes: 54 additions & 0 deletions src/guides/v2.4/graphql/queries/check-company-email.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
group: graphql
title: checkCompanyEmail query
b2b_only: true
---

The `checkCompanyEmail` query checks whether the specified email is valid for company registration. The specified email can be the same as an existing customer or company administrator. If the email matches an existing company email, the query returns a `false` value.

## Syntax

`checkCompanyEmail ( email String! ) CompanyEmailCheckResponse`

## Example usage

The following example checks whether the email address `roni_cost@example.com` can be used to register a company.

**Request:**

```graphql
query{
checkCompanyEmail(email: "roni_cost@example.com"){
isEmailValid
}
}
```

**Response:**

```json
{
"data": {
"checkCompanyEmail": {
"isEmailValid": true
}
}
}
```

## Input attribute

Attribute | Data Type | Description
--- | --- | ---
`email` | String! | The email address to check

## Output attribute

Attribute | Data Type | Description
--- | --- | ---
`isEmailValid` | Boolean | A value of `true` indicates the email address is available

## Related topics

* [checkCompanyAdminEmail query]({{page.baseurl}}/graphql/queries/check-company-admin-email.html)
* [checkCompanyUserEmail query]({{page.baseurl}}/graphql/queries/check-company-user-email.html)
54 changes: 54 additions & 0 deletions src/guides/v2.4/graphql/queries/check-company-user-email.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
group: graphql
title: checkCompanyUserEmail query
b2b_only: true
---

The `checkCompanyUserEmail` query checks whether an email is valid for registering a company user. The query returns a `false` value if the specified email matches the email of an existing customer or a company administrator.

## Syntax

`checkCompanyUserEmail ( email String! ) CompanyUserEmailCheckResponse`

## Example usage

The following example checks whether the email address `roni_cost@example.com` can be used to create a company user.

**Request:**

```graphql
query{
checkCompanyUserEmail(email: "roni_cost@example.com"){
isEmailValid
}
}
```

**Response:**

```json
{
"data": {
"checkCompanyUserEmail": {
"isEmailValid": false
}
}
}
```

## Input attribute

Attribute | Data Type | Description
--- | --- | ---
`email` | String! | The email address to check

## Output attribute

Attribute | Data Type | Description
--- | --- | ---
`isEmailValid` | Boolean | A value of `true` indicates the email address is available

## Related topics

* [checkCompanyEmail query]({{page.baseurl}}/graphql/queries/check-company-email.html)
* [checkCompanyAdminEmail query]({{page.baseurl}}/graphql/queries/check-company-admin-email.html)
194 changes: 194 additions & 0 deletions src/guides/v2.4/graphql/queries/company.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
---
group: graphql
title: company query
b2b_only: true
---

The `company` query returns details about the user's company. The request must include the customer token of a company user.

A company structure can contain multiple levels of teams, with company users assigned at each level. To query on a company structure, specify fragments on the `Customer` and `CompanyTeam` objects. Magento returns a [union](https://graphql.org/learn/schema/#union-types) of these objects. Specify the `__typename` attribute to distinguish the object types in the response.

## Syntax

`{company: {Company}}`

## Example usage

### Return information about a newly-created company

The following call returns basic information about the customer's company.

**Request:**

```graphql
query{
company{
company_admin {
firstname
lastname
email
}
email
id
legal_address {
street
city
region {
region_id
region_code
}
postcode
country_code
telephone
}
legal_name
name
}
}
```

**Response:**

```json
{
"data": {
"company": {
"company_admin": {
"firstname": "Taina",
"lastname": "Garofalo",
"email": "tgarofalo@example.com"
},
"email": "tgarofalo@example.com",
"id": "MQ==",
"legal_address": {
"street": [
"265 Cambridge Ave"
],
"city": "Palo Alto",
"region": {
"region_id": 12,
"region_code": "CA"
},
"postcode": "94306",
"country_code": "US",
"telephone": "555 867-5309"
},
"legal_name": "TestCo Inc.",
"name": "TestCo"
}
}
}
```

### Return the company structure

The following query returns the customer's company structure.

<!--- To do: Replace the response after creating a proper structure and add a tree depicting the structure -->

**Request:**

```graphql
query{
company{
id
name
structure{
items {
entity {
__typename
... on Customer {
firstname
lastname
email
}
... on CompanyTeam {
name
description
id
}
}
}
}
}
}
```

**Response:**

```json
{
"data": {
"company": {
"id": "Ng==",
"name": "TestCo2",
"structure": {
"items": [
{
"entity": {
"__typename": "Customer",
"firstname": "Taina",
"lastname": "Garofalo",
"email": "donadmin@example.com"
}
},
{
"entity": {
"__typename": "CompanyTeam",
"name": "Y Team",
"description": "Y Team description",
"id": "Ng=="
}
},
{
"entity": {
"__typename": "Customer",
"firstname": "B",
"lastname": "BB",
"email": "bbb@example.com"
}
},
{
"entity": {
"__typename": "CompanyTeam",
"name": "X team",
"description": "X team description",
"id": "Nw=="
}
},
{
"entity": {
"__typename": "Customer",
"firstname": "A",
"lastname": "AA",
"email": "aa@example.com"
}
},
{
"entity": {
"__typename": "CompanyTeam",
"name": "Z Team",
"description": "Z team description",
"id": "NQ=="
}
},
{
"entity": {
"__typename": "Customer",
"firstname": "C",
"lastname": "CC",
"email": "ccc@example.com"
}
}
]
}
}
}
}
```

## Output attributes

The `company` object returns the `Company` object.

{% include graphql/company.md %}