Gathering detailed insights and metrics for @capaj/typegql
Gathering detailed insights and metrics for @capaj/typegql
Gathering detailed insights and metrics for @capaj/typegql
Gathering detailed insights and metrics for @capaj/typegql
npm install @capaj/typegql
Typescript
Module System
TypeScript (98.82%)
JavaScript (1.18%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
426 Stars
140 Commits
19 Forks
7 Watchers
4 Branches
7 Contributors
Updated on Jun 21, 2025
Latest Version
0.6.5
Package Id
@capaj/typegql@0.6.5
Unpacked Size
4.46 MB
Size
2.20 MB
File Count
3,919
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
1
typegql
?typegql is set of decorators allowing creating GraphQL APIs quickly and in type-safe way.
Example below is able to resolve such query
1query { 2 hello(name: "Bob") # will resolve to 'Hello, Bob!' 3}
1import { Schema, Query, compileSchema } from 'typegql' 2 3@Schema() 4class SuperSchema { 5 @Query() 6 hello(name: string): string { 7 return `Hello, ${name}!` 8 } 9} 10 11const compiledSchema = compileSchema(SuperSchema)
compiledSchema
is regular executable schema compatible with graphql-js
library.
To use it with express
, you'd have to simply:
1import * as express from 'express' 2import * as graphqlHTTP from 'express-graphql' 3 4const app = express() 5 6app.use( 7 '/graphql', 8 graphqlHTTP({ 9 schema: compiledSchema, 10 graphiql: true, 11 }), 12) 13app.listen(3000, () => 14 console.log('Graphql API ready on http://localhost:3000/graphql'), 15)
For now, our query field returned scalar (string). Let's return something more complex. Schema will look like:
1mutation { 2 createProduct(name: "Chair", price: 99.99) { 3 name 4 price 5 isExpensive 6 } 7}
Such query will have a bit more code and here it is:
1import { 2 Schema, 3 Query, 4 ObjectType, 5 Field, 6 Mutation, 7 compileSchema, 8} from 'typegql' 9 10@ObjectType({ description: 'Simple product object type' }) 11class Product { 12 @Field() 13 name: string 14 15 @Field() 16 price: number 17 18 @Field() 19 isExpensive() { 20 return this.price > 50 21 } 22} 23 24@Schema() 25class SuperSchema { 26 @Mutation() 27 createProduct(name: string, price: number): Product { 28 const product = new Product() 29 product.name = name 30 product.price = price 31 return product 32 } 33} 34 35const compiledSchema = compileSchema(SuperSchema)
Since now, typegql
was able to guess type of every field from typescript type definitions.
There are, however, some cases where we'd have to define them explicitly.
number
type is Float
or Int
(GraphQLFloat
or GraphQLInt
) etcPromise<SomeType>
while field itself is typed as SomeType
Reflect
api is not able to guess type of single array item. This might change in the future)Let's modify our Product
so it has additional categories
field that will return array of strings. For sake of readibility, I'll ommit all fields we've defined previously.
1@ObjectType() 2class Product { 3 @Field({ type: [String] }) // note we can use any native type like GraphQLString! 4 categories(): string[] { 5 return ['Tables', 'Furniture'] 6 } 7}
We've added { type: [String] }
as @Field
options. Type can be anything that is resolvable to GraphQL
type
String
, Number
, Boolean
.graphql
eg. GraphQLFloat
or any type from external graphql library etc@ObjectType
[String]
or [GraphQLFloat]
Every field function we write can be async
and return Promise
. Let's say, instead of hard-coding our categories, we want to fetch it from some external API:
1@ObjectType() 2class Product { 3 @Field({ type: [String] }) // note we can use any native type like GraphQLString! 4 async categories(): Promise<string[]> { 5 const categories = await api.fetchCategories() 6 return categories.map((cat) => cat.name) 7 } 8}
1.0.0
Before version 1.0.0
consider APIs of typegql
to be subject to change. We encourage you to try this library out and provide us feedback so we can polish it to be as usable and efficent as possible.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/19 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
178 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More