Skip to content

Commit

Permalink
feat: remote fields support (#25)
Browse files Browse the repository at this point in the history
* feat: add support for remote fields

* fix: update schema

Co-authored-by: Daniel Winter <[email protected]>
  • Loading branch information
BrunoScheufler and Daniel Winter authored Mar 18, 2022
1 parent 0554211 commit 2d704e9
Show file tree
Hide file tree
Showing 8 changed files with 1,612 additions and 469 deletions.
51 changes: 0 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,42 +243,6 @@ To delete an enumeration and it's values
migration.deleteEnumeration(apiId);
```

## Remote Type Definitions

Remote fields allow you to define an external resolver through the management SDK. Remote fields consist of two parts, defining any custom type that will represent the returning shape from the external resolver, defining the resolver itself.

### Create a Remote Type Definition

Create a sample Remote Type Definition for Github API.

```js
migration.createRemoteTypeDefinition({
definition:
"type Github { id: Int!, login: String!, name: String!, company: String, bio: String, blog: String, location: String }",
displayName: "Github profile",
description: "Developer's Github profile",
});
```

### Update a Remote Type Definition

To update a Remote Type Definition

```js
migration.updateRemoteTypeDefinition({
apiId:
... // properties to update
});
```

### Delete a Remote Type Definition

To delete a Remote Type Definition

```js
migration.deleteRemoteTypeDefinition(apiId);
```

## Models

Your schema is defined by the models you create, and fields you add.
Expand Down Expand Up @@ -410,21 +374,6 @@ model.addUnionField({
});
```

To create a remote field.

```js
model.addRemoteField({
apiId,
displayName,
remoteConfig: {
method, // one of GET (default), POST or PUT.
payloadFieldApiIds, // Array<String> of field API IDs to send as part of request payload
returnType, // previously declared remote type definition
url, // url to fetch the remote data from
},
});
```

#### Update a Field

To update a field, firstly retrieve the model.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint --ignore-pattern src/generated/**",
"format": "tsdx lint --ignore-pattern src/generated/** --fix",
"prepare": "graphql-codegen && tsdx build",
"size": "size-limit",
"analyze": "size-limit --why",
Expand Down
Loading

0 comments on commit 2d704e9

Please sign in to comment.