Skip to content

Commit

Permalink
split the basic example into basic and with-UDF
Browse files Browse the repository at this point in the history
  • Loading branch information
zvictor committed Apr 15, 2020
1 parent bbf2ce5 commit 947ff0a
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 7 deletions.
3 changes: 0 additions & 3 deletions examples/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const sdk = faugra()
const random = () => Math.random().toString(36).substring(7)

async function main() {
log(await sdk.sayHello({ name: 'dimension C-137' }))

log(await sdk.createUser({ username: `rick-sanchez-${random()}` }))
log(await sdk.createUser({ username: `morty-smith-${random()}` }))

Expand All @@ -21,7 +19,6 @@ main()

// Expected output of this script:

// { sayHello: 'Hello dimension C-137' }
// { createUser: { _id: '262820989366174226' } }
// { createUser: { _id: '262820990060331538' } }
// { username: 'rick-sanchez' }
Expand Down
4 changes: 0 additions & 4 deletions examples/basic/queries.gql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ query allUsers {
}
}
}

query sayHello($name: String!) {
sayHello(name: $name)
}
3 changes: 3 additions & 0 deletions examples/with-UDF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.d.ts
faugra.sdk.ts
package-lock.json
13 changes: 13 additions & 0 deletions examples/with-UDF/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This example contains:

- a User-Defined Function (UDF) [sayHello.fql]
- a Graphql schema [Schema.graphql]
- a Graphql operations document [queries.gql]

By running `npx faugra --secret <MY_FAUNA_SECRET>` you should expect to see:

- The UDF uploaded to the cloud
- a TypeScript typings file generated per schema [Schema.d.ts]
- a requests sdk containing all the operations, fully typed and with auto-complete support [faugra.sdk.ts]

Once your `faugra.sdk.ts` has been generated, you can run `FAUGRA_SECRET=<MY_FAUNA_SECRET> npm start` to see the operations demo.
3 changes: 3 additions & 0 deletions examples/with-UDF/Schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Query {
sayHello(name: String!): String! @resolver(name: "sayHello")
}
7 changes: 7 additions & 0 deletions examples/with-UDF/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import faugra from './faugra.sdk'

faugra().sayHello({ name: 'dimension C-137' }).then(console.log)

// Expected output of this script:

// { sayHello: 'Hello dimension C-137' }
16 changes: 16 additions & 0 deletions examples/with-UDF/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "faugra-example",
"version": "1.0.0",
"scripts": {
"start": "npx ts-node index.ts"
},
"dependencies": {
"faugra": "../..",
"graphql-request": "^1.8.2"
},
"devDependencies": {
"@types/node": "^12.12.2",
"ts-node": "^8.8.2",
"typescript": "^3.8.3"
}
}
3 changes: 3 additions & 0 deletions examples/with-UDF/queries.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query sayHello($name: String!) {
sayHello(name: $name)
}
File renamed without changes.
1 change: 1 addition & 0 deletions examples/with-user-defined-functions

0 comments on commit 947ff0a

Please sign in to comment.