The Graphweaver Microsoft Dynamics integration is an enterprise solution. The package exists in the private Graphweaver enterprise repo. Please get in contact with us if you wish to use the packages in this repo.
Prerequisites
To connect Graphweaver to Microsoft Dynamics, you must create or have access to a Microsoft Dynamics environment to connect to.
Sign up for a free trial at https://dynamics.microsoft.com/en-au/dynamics-365-free-trial/
Setting Up Microsoft Dynamics Free Trial Account
1. Sign up for Dynamics 365 Free Trial
Visit the Microsoft Dynamics 365 Free Trial page and follow the prompts to sign up for a free trial account.
Once the Dynamics instance has been created note the server name in the URL and set this as CRM_HOST
environment variable.
The URL should look something like this: orgfb25dxxxxx.crm6.dynamics.com
.
Next, we need to create an application to make API requests to this instance.
2. Create an App Registration for Dynamics 365
2.1. Navigate to Azure Portal
- Go to Azure Portal.
2.2. Create a new App Registration
- In the left sidebar, select "Azure Active Directory."
- Navigate to "App registrations" and click on "New registration."
- Fill in the necessary details:
- Name: Enter a name for your app registration.
- Supported account types: Choose "Accounts in this organizational directory only."
- Redirect URI: set to http://localhost:9000.
2.3. Note down the Application (client) ID and Tenant ID
- Once the app registration is created, note down the "Application (client) ID." as this is used for the
CRM_CLIENT_ID
environment variable. - Note down the Tenant ID as this is used as part of the URL in the
CRM_OAUTH_ENDPOINT
environment variable. Replace[INSERT_TENANT_ID]
in this stringhttps://login.windows.net/[INSERT_TENANT_ID]/oauth2/token
2.4. Generate Client Secret
- In the app registration settings, go to "Certificates & Secrets" and create a new client secret.
- Note down the generated value as this is used for the
CRM_CLIENT_SECRET
environment variable.
3. Create a User in Office 365
3.1. Navigate to Microsoft 365 Admin Center
- Visit the Microsoft 365 Admin Center.
3.2. Add a new user
- In the left sidebar, go to "Users" and click on "Active users."
- Click on "Add a user" and fill in the required details for the new user.
3.3. Assign a Dynamics 365 license
- After creating the user, assign a Dynamics 365 license to the user by going to "Licenses".
4. Grant Permissions in Power Apps
4.1. Navigate to the Power Platform Admin Center
- Go to the Power Platform Admin Center.
4.2. Select the environment
- Choose the environment related to your Dynamics 365 instance.
4.3. Manage Users
- Navigate to "Users" and find the user you created earlier.
4.4. Assign a security role
- Assign the "System Administrator" security role for the user.
Creating a Microsoft Dynamics Connection
Now that we have our Dynamics Server there are a few steps to follow to support our first entity:
- Create a Dynamics Data Entity
- Create a GraphQL Entity for the Data Entity created in Step 1
- Finally, Create a Resolver attached to the GraphQL entity
First, the Dynamics Data Entity looks like this:
import { Field, BaseEntity } from "@exogee/graphweaver-microsoft-dynamics";
export class CrmContact extends BaseEntity {
static entityPath = "contacts";
static entityName = "contact";
static typeName = "Contact";
@Field({ underlyingFieldName: "contactid" })
id!: string;
@Field()
firstname?: string;
@Field()
lastname?: string;
}
In the above, we have created a Contact entity that represents the Contact found in Dynamics.
Next, letโs create a GraphQL entity that uses this Data Entity.
import {
GraphQLEntity,
SummaryField,
Field,
ID,
ObjectType,
} from "@exogee/graphweaver";
import { CrmContact } from "../../entities/dynamics";
@Entity("Contact", {
provider: new OdataBackendProvider(CrmContact)
})
export class Contact extends GraphQLEntity<CrmContact> {
@Field(() => ID)
id!: string;
@Field(() => String, { nullable: true })
firstname?: string;
@Field(() => String, { nullable: true })
lastname?: string;
}
As you can see in this example we have mapped the data fields to the GraphQL fields.
Now that we have created this entity we can start the Graphweaver server:
/* microsoft-dynamics Graphweaver Project */
import 'reflect-metadata';
import Graphweaver from '@exogee/graphweaver-server';
import './schema';
export const graphweaver = new Graphweaver();
export const handler = graphweaver.handler();