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

GraphQL: Add coverage for create/updateCompany mutations #7949

Merged
merged 5 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
10 changes: 10 additions & 0 deletions src/_data/toc/graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ pages:
- label: createBraintreeClientToken mutation
url: /graphql/mutations/create-braintree-client-token.html

- label: createCompany mutation
url: /graphql/mutations/create-company.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: createCustomer mutation
url: /graphql/mutations/create-customer.html

Expand Down Expand Up @@ -327,6 +332,11 @@ pages:
- label: updateCartItems mutation
url: /graphql/mutations/update-cart-items.html

- label: updateCompany mutation
url: /graphql/mutations/update-company.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: updateCustomer mutation
url: /graphql/mutations/update-customer.html

Expand Down
99 changes: 99 additions & 0 deletions src/_includes/graphql/company.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
The `Company` object can contain the following attributes:

Attribute | Data type | Description
--- | --- | ---
`acl_resources` [CompanyAclResource] | Returns the list of all resources defined within the company
`company_admin` | [Customer]({{page.baseurl}}/graphql/queries/customer.html) | An object containing information about the company administrator
`email` | String | The email address of the company contact
`id` | ID! | The ID assigned to the company
`legal_address` | CompanyLegalAddress | The address where the company is registered to conduct business
`legal_name` | String | The full legal name of the company
`name` | String | The name of the company
`payment_methods` | [String] The list of payment methods available to a company
`reseller_id` | String | The resale number that is assigned to the company for tax reporting purposes
`role(id: ID!)` | CompanyRole | Returns information about the specified company role
`roles(pageSize: Int = 20, currentPage: Int = 1 )` | CompanyRoles! | Returns the list of company roles
`sales_representative` | CompanySalesRepresentative | The company sales representative
`structure(rootId: ID = 0 depth: Int = 10 )` | CompanyStructure | Returns the company structure of teams and customers in depth-first order
`team(id: ID!)` | CompanyTeam | Returns the specified company team
`user(id: ID!)` | Customer | Returns the specified company user
`users(filter: CompanyUsersFilterInput, pageSize: Int = 20, currentPage: Int = 1)`| CompanyUsers | Returns the company users that match the specified filter
`vat_id` | String | The value-added tax number that is assigned to the company by some jurisdictions for tax reporting purposes

### CompanyAclResource attributes {#CompanyAclResource}

The `CompanyAclResource` object can contain the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`children` | [CompanyAclResource!] | An array of sub-resources
`id` | ID! | The ID assigned to the ACL resource
`sortOrder` | Int | ACL resource sort order
`text` | String | The label assigned to the ACL resource

### CompanyAdmin attributes {#CompanyAdmin}

The `CompanyAdmin` object can contain the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`email` | String! | The email address of the company administrator
`firstname` | String! | The company administrator's first name
`gender` | Int | The company administrator's gender (Male - 1, Female - 2, Not Specified - 3)
`id` | ID! | The ID assigned to the company administrator
`job_title` | String | The job title of the company administrator
`lastname` | String! | The company administrator's last name

### CompanyLegalAddress attributes {#CompanyLegalAddress}

The `CompanyLegalAddress` object can contain the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`city` | String! | The city where the company is registered to conduct business
`country_id` | CountryCodeEnum! | Company's country ID. See the [`countries` query]({{page.baseurl}}/graphql/queries/directory-countries.html)
`postcode` | String! | The ZIP/postal code of the company
`region` | CustomerAddressRegionInput! | An object containing the region name and/or region ID where the company is registered to conduct business
`street` | [String!]! | An array of strings that define the street address where the company is registered to conduct business
`telephone` | String! | The primary phone number of the company.

### CompanyRole attributes {#CompanyRole}

The `CompanyRole` object can contain the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`id`| ID! | The ID assigned to the role
`name` | String | The name assigned to the role
`permissions` | [CompanyAclResource] | A list of permission resources defined for a role
`users_count` | Int | The total number of users assigned the specified role

### CompanyRoles attributes {#CompanyRoles}

The `CompanyRoles` object can contain the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`items` | [CompanyRole] | A list of company roles that match the specified filter criteria
`page_info` | SearchResultPageInfo | Pagination meta data
`total_count` | Int | The total number of roles matching the specified filter

### CompanySalesRepresentative attributes {#CompanySalesRepresentative}

The `CompanySalesRepresentative` object can contain the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`email` | String! | The email address of the company sales representative
`firstname` | String! | The company sales representative's first name
`lastname` | String! | The company sales representative's last name

### CompanyUsers attributes {#CompanyUsers}

The `CompanyUsers` object can contain the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`items` | [[Customer]]({{page.baseurl}}/graphql/queries/customer.html) | An array of `CompanyUser` objects that match the specified search criteria
`page_info` | SearchResultPageInfo | Pagination meta data
`total_count` | Int | The number of objects returned
10 changes: 10 additions & 0 deletions src/_includes/graphql/customer-output-24.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ Attribute | Data Type | Description
`suffix` | String | A value such as Sr., Jr., or III
`taxvat` | String | The customer's Tax/VAT number (for corporate customers)
`wishlist` | Wishlist! | Contains the contents of the customer's wish lists

For B2B, company users can have the following attributes.

Attribute | Data Type | Description
--- | --- | ---
`job_title` | String | The job title for a B2B company user
`role`| CompanyRole | The role name and permissions assigned to the company user
`status` | CompanyUserStatusEnum | Indicates whether the company user is ACTIVE or INACTIVE
`team` | CompanyTeam | The team the company user is assigned to
`telephone` | String | The phone number of the company user
154 changes: 154 additions & 0 deletions src/guides/v2.4/graphql/mutations/create-company.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
---
group: graphql
title: createCompany mutation
b2b_only: true
---

The `createCompany` mutation creates a company at the request of either a customer or a guest. The company definition includes the first name, last name, and email address of the company administrator. The email address assigned to the account cannot already exist in the system. Therefore, a customer attempting to create a company cannot use the same email address they used to log in to the storefront.

The company administrator cannot log in or perform additional company-related tasks until a Magento administrator approves the request to create a company.

## Syntax

```graphql
mutation {
createCompany(
input: CompanyCreateInput!
) {
CreateCompanyOutput
}
}
```
## Example usage

The following call creates a company on behalf of a guest.

**Request:**

```graphql
mutation {
createCompany(input: {
company_name: "TestCo"
company_email: "tgarofalo@example.com"
company_admin: {
email: "tgarofalo@example.com"
firstname: "Taina"
lastname:"Garofalo"
}
legal_name: "TestCo Inc."
legal_address: {
street: [
"100 Big Oak Tree Dr"
]
city: "San Francisco"
region: {
region_code: "CA"
}
postcode: "99999"
country_id: US
telephone: "555 867-5309"
}
}){
company {
id
name
company_admin {
email
firstname
lastname
}
legal_address {
street
city
region {
region_code
region_id
}
postcode
telephone
}
}
}
}
```

**Response:**

```json
{
"data": {
"createCompany": {
"company": {
"id": "MQ==",
"name": "TestCo",
"company_admin": {
"email": "tgarofalo@example.com",
"firstname": "Taina",
"lastname": "Garofalo"
},
"legal_address": {
"street": [
"100 Big Oak Tree Dr"
],
"city": "San Francisco",
"region": {
"region_code": "CA",
"region_id": 12
},
"postcode": "99999",
"telephone": "555 867-5309"
}
}
}
}
}
```

## Input attributes

The CompanyCreateInput object defines the schema for creating an entity.

Attribute | Data Type | Description
--- | --- | ---
`company_admin` | [CompanyAdminInput!](#CompanyAdminInput) | Defines the company administrator
`company_email` | String! | The email address of the company contact
`company_name` | String! | The company name
`legal_address` | [CompanyLegalAddressCreateInput!](#CompanyLegalAddressCreateInput) | Defines legal address data of the company
`legal_name` | String | The full legal name of the company
`reseller_id` | String | The resale number that is assigned to the company for tax reporting purposes
`vat_tax_id` | String | The value-added tax number that is assigned to the company by some jurisdictions for tax reporting purposes

### CompanyAdminInput attributes {#CompanyAdminInput}

The `CompanyAdminInput` object can contain the following attributes.

Attribute | Data Type | Description
--- | --- | ---
`email` | String! | The email address of the company administrator
`firstname` | String! | The company administrator's first name
`gender` | Int | The company administrator's gender (Male - 1, Female - 2, Not Specified - 3)
`job_title` | String | The job title of the company administrator
`lastname` | String! | The company administrator's last name

### CompanyLegalAddressCreateInput attributes {#CompanyLegalAddressCreateInput}

The `CompanyLegalAddressCreateInput` object can contain the following attributes.

Attribute | Data Type | Description
--- | --- | ---
`city` | String! | The city where the company is registered to conduct business
`country_id` | CountryCodeEnum! | Company's country ID. See the [`countries` query]({{page.baseurl}}/graphql/queries/directory-countries.html)
`postcode` | String! | The ZIP/postal code of the company
`region` | CustomerAddressRegionInput! | An object containing the region name and/or region ID where the company is registered to conduct business
`street` | [String!]! | An array of strings that define the street address where the company is registered to conduct business
`telephone` | String! | The primary phone number of the company

## Output attributes

The `CreateCompanyOutput` object contains the `Company` object.

{% include graphql/company.md %}

## Related topics

* [updateCompany mutation]({{page.baseurl}}/graphql/mutations/update-company.html)
Loading