# datasource-zendesk

A [`RESTDataSource`](https://www.apollographql.com/docs/apollo-server/data/data-sources/#rest-data-source) for
interacting with [Zendesk](https://www.zendesk.com/).

## Usage

### Configuring the Connector

```js
import { Zendesk } from '@theorchard/datasource-zendesk';

const config = {
    zendeskUrl: 'https://theorchardproduct.zendesk.com',
    zendeskApiToken: 'secretsecretsecret',
    zendeskApiEmail: 'zendesk-orchard-api@theorchard.com',
};

const zendesk = new Zendesk(config);
```

### Create a Request

```js
const result = await zendesk.createRequest({
    subject: 'A user needs help!',
    comment: 'The user lit their computer on fire',
    assigneeId: 430485019873,
    requester: {
        email: 'jfowler@theorchard.com',
        name: 'Jacob Fowler',
    },
});

console.log(result.url);
```

### Extending `ZendeskDataSource`

Most of the time when using GraphQL, you probably want to extend the data source and wire it into your connectors (the
same thing we do for REST all over the place). This will likely look similar to the following:

```js
import { ZendeskDataSource } from '@theorchard/datasource-zendesk';

class Zendesk extends ZendeskDataSource {
    async reportComputerFire({
        requester,
        fire: {
            temperature: { value, units },
        },
    }) {
        return this.createRequest({
            subject: 'User has a computer fire!',
            comment: `Fire is raging at ${value}°${units}!`,
            requester,
        });
    }
}

export default Zendesk;
```

As long as your config object has the Zendesk properties as defined above, this should work without adding a
`constructor` to the class. Neat!
