mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
168 lines
5.0 KiB
Markdown
168 lines
5.0 KiB
Markdown
# The Graph TypeScript Library (graph-ts)
|
|
|
|
[](https://www.npmjs.com/package/@graphprotocol/graph-ts)
|
|
[](https://travis-ci.org/graphprotocol/graph-ts)
|
|
|
|
TypeScript/AssemblyScript library for writing subgraph mappings to be
|
|
deployed to [The Graph](https://github.com/graphprotocol/graph-node).
|
|
|
|
## Usage
|
|
|
|
For a detailed guide on how to create a subgraph, please see the
|
|
[Graph CLI docs](https://github.com/graphprotocol/graph-cli).
|
|
|
|
One step of creating the subgraph is writing mappings that will process
|
|
blockchain events and will write entities into the store. These mappings
|
|
are written in TypeScript/AssemblyScript.
|
|
|
|
The `graph-ts` library provides APIs to access the Graph Node store,
|
|
blockchain data, smart contracts, data on IPFS, cryptographic functions
|
|
and more. To use it, all you have to do is add a dependency on it:
|
|
|
|
```sh
|
|
npm install --dev @graphprotocol/graph-ts # NPM
|
|
yarn add --dev @graphprotocol/graph-ts # Yarn
|
|
```
|
|
|
|
After that, you can import the `store` API and other features from
|
|
this library in your mappings. A few examples:
|
|
|
|
```typescript
|
|
import { store, crypto } from '@graphprotocol/graph-ts'
|
|
|
|
// This is just an example event type generated by `graph-cli`
|
|
// from an Ethereum smart contract ABI
|
|
import { NameRegistered } from './types/abis/SomeContract'
|
|
|
|
// This is an example of an entity type generated from a
|
|
// subgraph's GraphQL schema
|
|
import { Domain } from './types/schema'
|
|
|
|
function handleNameRegistered(event: NameRegistered) {
|
|
// Example use of a crypto function
|
|
let id = crypto.keccak256(name).toHexString()
|
|
|
|
// Example use of the generated `Entry` class
|
|
let domain = new Domain()
|
|
domain.name = name
|
|
domain.owner = event.params.owner
|
|
domain.timeRegistered = event.block.timestamp
|
|
|
|
// Example use of the store API
|
|
store.set('Name', id, entity)
|
|
}
|
|
```
|
|
|
|
## Helper Functions for AssemblyScript
|
|
|
|
Refer to the `helper-functions.ts` file in this repository for a few common functions that help build on top of the AssemblyScript library, such as byte array concatenation, among others.
|
|
|
|
## API
|
|
|
|
Documentation on the API can be found [here](https://thegraph.com/docs/assemblyscript-api#api-reference).
|
|
|
|
For examples of `graph-ts` in use take a look at one of the following subgraphs:
|
|
* https://github.com/graphprotocol/ens-subgraph
|
|
* https://github.com/graphprotocol/decentraland-subgraph
|
|
* https://github.com/graphprotocol/adchain-subgraph
|
|
* https://github.com/graphprotocol/0x-subgraph
|
|
* https://github.com/graphprotocol/aragon-subgraph
|
|
* https://github.com/graphprotocol/dharma-subgraph
|
|
|
|
## Release process
|
|
|
|
The steps to create a new version of the `graph-ts` are:
|
|
|
|
1. Decide which version number you'll be rolling out. You can check the differences between the current `master` branch and the latest release.
|
|
2. Create a PR with the commit generated by `npm version <VERSION> [<PREID>]`.
|
|
3. Once that's approved and merged to `master`, you can publish it to `npm` and push the git tags as well.
|
|
4. Last but not least, create a Github Release refering to the pushed git tag, linking to the PRs involved.
|
|
|
|
Helpful links:
|
|
|
|
- [Semver official docs](https://semver.org/)
|
|
- [`npm version` docs](https://docs.npmjs.com/cli/v7/commands/npm-version)
|
|
- [`npm publish` docs](https://docs.npmjs.com/cli/v7/commands/npm-publish)
|
|
- [`npm unpublish` docs](https://docs.npmjs.com/cli/v7/commands/npm-unpublish)
|
|
- [`npm deprecate` docs](https://docs.npmjs.com/cli/v7/commands/npm-deprecate)
|
|
|
|
### Stable release example
|
|
|
|
Current version: `0.34.9`.
|
|
Desired release: `0.35.0`.
|
|
|
|
To create the PR:
|
|
```
|
|
git checkout -b <BRANCH>
|
|
|
|
npm version minor
|
|
|
|
git push --set-upstream <REMOTE> <BRANCH>
|
|
```
|
|
|
|
Once that's approved and merged, you can update your local `master` and:
|
|
|
|
```
|
|
npm publish
|
|
|
|
npm push --tags
|
|
```
|
|
|
|
### Alpha release example
|
|
|
|
Current version: `0.29.2`.
|
|
Desired release: `0.30.0-alpha.0`.
|
|
|
|
To create the PR:
|
|
```
|
|
git checkout -b <BRANCH>
|
|
|
|
npm version preminor --preid alpha
|
|
|
|
git push --set-upstream <REMOTE> <BRANCH>
|
|
```
|
|
|
|
Once that's approved and merged, you can update your local `master` and:
|
|
|
|
```
|
|
npm publish --tag alpha
|
|
|
|
npm push --tags
|
|
```
|
|
|
|
### Alpha pre-release example
|
|
|
|
Current version: `0.30.0-alpha.0`.
|
|
Desired release: `0.30.0-alpha.1`.
|
|
|
|
To create the PR:
|
|
```
|
|
git checkout -b <BRANCH>
|
|
|
|
npm version prerelease --preid alpha
|
|
|
|
git push --set-upstream <REMOTE> <BRANCH>
|
|
```
|
|
|
|
Once that's approved and merged, you can update your local `master` and:
|
|
|
|
```
|
|
npm publish --tag alpha
|
|
|
|
npm push --tags
|
|
```
|
|
|
|
## License
|
|
|
|
Copyright © 2018 Graph Protocol, Inc. and contributors.
|
|
|
|
The Graph TypeScript library is dual-licensed under the
|
|
[MIT license](LICENSE-MIT) and the
|
|
[Apache License, Version 2.0](LICENSE-APACHE).
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|