Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fusion & GraphClient #628

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 0 additions & 20 deletions examples/composition/.graphclientrc.yml

This file was deleted.

1 change: 1 addition & 0 deletions examples/composition/fusiongraph.ts

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions examples/composition/graphclient.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
createRenameFieldTransform,
createRenameTypeTransform,
defineConfig as defineComposeConfig,
loadGraphQLHTTPSubgraph,
} from '@graphprotocol/client-compose-cli'
import { GraphQLID } from 'graphql'

export const composeConfig = defineComposeConfig({
subgraphs: [
{
sourceHandler: loadGraphQLHTTPSubgraph('nft', {
endpoint: 'https://api.thegraph.com/subgraphs/name/amxx/eip721-subgraph',
}),
transforms: [
// Resolve conflicts between subgraphs
createRenameFieldTransform((field, fieldName, typeName) => {
if (typeName === 'Account' && fieldName === 'id') {
field.type = GraphQLID
}
return fieldName
}),
createRenameTypeTransform((type) => {
if (type.name === 'Account') {
return 'User'
}
return type.name
}),
],
},
{
sourceHandler: loadGraphQLHTTPSubgraph('uniswap', {
endpoint: 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2',
}),
},
],
})
9 changes: 5 additions & 4 deletions examples/composition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"version": "0.0.0",
"scripts": {
"start": "ts-node --transpileOnly src/index.ts",
"build-client": "graphclient build",
"check": "tsc --pretty --noEmit",
"graphiql": "graphclient serve-dev"
"graphiql": "node ../../packages/serve-cli/dist/cjs/bin.js",
"build": "node ../../packages/compose-cli/dist/cjs/bin.js"
},
"dependencies": {
"@graphprotocol/client-cli": "^3.0.0",
"@graphql-mesh/transform-rename": "^0.94.0",
"@graphprotocol/client-compose-cli": "^0.0.0",
"@graphprotocol/client-runtime": "^0.0.0",
"@graphql-mesh/transport-http": "^0.1.4",
"concurrently": "^8.0.1",
"graphql": "^16.6.0",
"nodemon": "^3.0.0",
Expand Down
45 changes: 31 additions & 14 deletions examples/composition/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { execute } from '../.graphclient'
import { getExecutor } from '@graphprotocol/client-runtime'
import fusiongraph from '../fusiongraph'
import { parse } from 'graphql'

const executor = getExecutor({
fusiongraph,
})

async function main() {
const response = await execute(
/* GraphQL */ `
const response = await executor({
document: parse(/* GraphQL */ `
fragment UserFields on User {
# Shared unique identifier field
id
# Field from uniswap source
tokens(first: 1) {
ERC721tokens(first: 1001) {
# Testing auto pagination by exceeding the limit of 1000
id
uri
registry {
id
}
}
# Field from nft source
liquidityPositions(first: 1) {
Expand All @@ -26,15 +30,28 @@ async function main() {
...UserFields
}
# Get base entity from uniswap source
user(id: "0x72ba1965320ab5352fd6d68235cc3c5306a6ffa2") {
...UserFields
}
# user(id: "0x72ba1965320ab5352fd6d68235cc3c5306a6ffa2") {
# ...UserFields
#}
}
`,
{},
)
`),
})

if (Symbol.asyncIterator in response) {
throw new Error('Unexpected async iterator response')
}

console.log(response)
if ('errors' in response && response.errors?.length) {
for (const error of response.errors) {
console.error(error.message)
}
} else {
console.log(`
Account: ${response.data?.account.id} has
${response.data?.account.ERC721tokens.length} ERC721 tokens and
${response.data?.account.liquidityPositions.length} liquidity positions
`)
}
}

main().catch((e) => console.error(`Failed to run example:`, e))
2 changes: 1 addition & 1 deletion examples/composition/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"lib": ["esnext", "DOM", "DOM.Iterable"],
"allowSyntheticDefaultImports": true
},
"files": ["src/index.ts"]
"files": ["src/index.ts", "graphclient.config.ts"]
}
2 changes: 1 addition & 1 deletion examples/transforms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"@graphprotocol/client-cli": "^3.0.0",
"@graphql-mesh/transform-prefix": "^0.94.0",
"@graphql-mesh/transform-prefix": "^0.97.4",
"graphql": "^16.6.0"
}
}
Loading