TypeScript Example?

Are there any examples available for TypeScript?

What are you trying to do? It’s basically the same as js but with types of course.

Or are you just looking for help on how to use the Fauna types? They are not very specific, pretty much everything being Expr or ExprArg

I wrote these packages in typescript.

faunad-io-types helps you build validators/decoder for io-ts and easy integration with fp-ts. I have code using it but haven’t added it as an example to the repo yet.

Typescript is taking over the JavaScript world by storm according to recent polls (and rightfully so in my humble opinion). I’ve written all my current examples in JavaScript since I wanted people to get into it easily.

I’ll keep it in the back of my mind that if I start a new example in the near future, to write it in TypeScript.

1 Like

https://github.com/ptpaterson/faunadb-io-types looks cool. Do you have any examples yet of how to use it? Thanks.

Do FaunaDB have Response Type in Typescript? I’m finding it’s redundant and not standardized when trying to make Response type especially with Ref, data, and ts key format in Fauna.

Do you have an example? That would be great. Thank you.

@ronyfhebrian,

Generally you don’t want to return every field from a GQL query. You should query only what you need in order to keep the network traffic low.

For example here is one of my response types. The number of fields in the response is very low compared to what is in the documents:

export interface FindPublicAndPrivatePiersResponse {
    data: {
        publicPiersAllUsers: {
            data: {
                _id: string;
                description: {
                    pierName: string;
                };
                observatory: {
                    description: {
                        observatoryName: string;
                    };
                };
            }[];
        };
        ownedObservatoriesThisUser: {
            ownedObservatories: {
                data: {
                    description: {
                        observatoryName: string;
                    };
                    piers: {
                        data: {
                            _id: string;
                            description: {
                                pierName: string;
                            };
                        }[];
                    };
                }[];
            };
        };
    };
}

Here is the query:

  findPublicAndPrivatePiers(username: string): Observable<FindPublicAndPrivatePiersResponse> {
    const query = `
    query {
      publicPiersAllUsers: findPiersByPublicFlag(isPublic: true) {
        data {
          _id
          description {
            pierName
          }
          observatory {
            description {
              observatoryName
            }
          }
        }
      }
      ownedObservatoriesThisUser: findObserverByUsername(username: "${ username }") {
        ownedObservatories {
          data {
            description {
              observatoryName
            }
            piers {
              data {
                _id
                description {
                  pierName
                }
              }
            }
          }
        }
      }
    }`;
    return this.executeQuery(query);
  }

As you can see, your query can also return related documents so it is not possible to generalize the Response type, at least this something that Fauna can’t do for you.