https://github.com/shiftx/faunadb-graphql-lib
https://github.com/shiftx/faunadb-graphql-lib
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/shiftx/faunadb-graphql-lib
- Owner: shiftx
- License: mit
- Created: 2020-02-17T08:09:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-11T21:23:53.000Z (almost 6 years ago)
- Last Synced: 2025-03-07T01:48:48.036Z (over 1 year ago)
- Language: TypeScript
- Size: 40.3 MB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# faunadb-graphql-lib
A collection of types and utilites to for building GraphQL endpoints
backed by FaunaDB.
### Helpers
#### generateFaunaQuery
Given a GraphQLResolveInfo and a Fauna query that produces a result matching the output type of a GraphQL query or muation, this will generate a single FQL query that fetches fields and related data requested in the GraphQL query.
```JavaScript
import { generateFaunaQuery } from "faunadb-graphql-lib"
{
readPost: {
type: PostType,
args: {
id: { type: PostIdType },
},
resolve: (_, { id }, context, info) => {
const query = generateFaunaQuery(info, q.Get(id))
return createClient()
.query(query)
.catch(err => {
console.log(err)
throw err
})
},
}
}
```
### GraphQL Types
#### GraphQLFaunaCollectionType
#### `GraphQLFaunaCollectionType`
```JavaScript
new GraphQLFaunaCollectionType({
name: "Post",
collectionName: "Posts",
fields: () => ({
id: { type: PostIdType },
title: { type: GraphQLString },
author: {
type: UserType,
},
attachments: {
type: AttachmentPageType,
fql: q =>
// Just return index?
q.GetAll(
q.Paginate(
q.Match(
q.Index("Attachments_by_postRef"),
q.SelectRef(q.Var("_item_"))
)
)
),
},
}),
})
```