Gathering detailed insights and metrics for decapi
Gathering detailed insights and metrics for decapi
Gathering detailed insights and metrics for decapi
Gathering detailed insights and metrics for decapi
prisma-decapi-class-generator
Prisma generator for generating Decapi class types and enums
decapitable
 [](https://opensource.org/licenses/MIT) [ for every word in a sentence.
npm install decapi
Typescript
Module System
Min. Node Version
TypeScript (99.4%)
JavaScript (0.6%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
82 Stars
421 Commits
1 Forks
4 Watchers
23 Branches
2 Contributors
Updated on Feb 26, 2025
Latest Version
2.1.2
Package Id
decapi@2.1.2
Unpacked Size
1.01 MB
Size
194.21 kB
File Count
715
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
1
decapi
?decapi is a set of decorators for creating GraphQL APIs in typescript. Write your types and GQL schema at once killing two birds with one stone.
Example below is able to resolve such query
1query { 2 hello(name: "Bob") # will resolve to 'Hello, Bob!' 3}
1import { SchemaRoot, Query, compileSchema } from 'decapi' 2 3@SchemaRoot() 4class SuperSchema { 5 @Query() 6 hello(name: string): string { 7 return `Hello, ${name}!` 8 } 9} 10 11const compiledSchema = compileSchema(SuperSchema)
compiledSchema
is a regular GQL executable schema compatible with graphql-js
library.
To use it with apollo-server
, you'd have to use like this:
1import ApolloServer from 'apollo-server' 2 3const server = new ApolloServer({ schema, graphiql: true }) 4 5server.listen(3000, () => 6 console.log('Graphql API ready on http://localhost:3000/graphql') 7)
Although it is encouraged to prefer fastify as it is a bit faster when used with jit.
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 SchemaRoot, 3 Query, 4 ObjectType, 5 Field, 6 Mutation, 7 compileSchema 8} from 'decapi' 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@SchemaRoot() 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)
These cases are supported by decapi 2/typescript-rtti:
Promise<SomeType>
All other code-first libraries on decorators like typegraphql or typegql require you to write types for these twice. Decapi infers types from typescript without any extra effort on your end.
Even in decapi 2 onward you still can write an explicit type. There are situations when typescript types are not precise enough- for example you want to be explicit about if some number
type is Float
or Int
(GraphQLFloat
or GraphQLInt
).
Let's modify our Product
so it has additional categories
field that will return array of strings. For the sake of readability, let's 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
, Date
.graphql
eg. GraphQLFloat
or any type from external graphql library etc@ObjectType
registerEnum
[String]
or [GraphQLFloat]
or [MyEnum]
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}
Firstly, you must install all the new peer dependencies.
This major was a complete rewrite of the reflection of types. From 2.0.0 decapi uses typescript-rtti to infer graphql types from typescript. This should work for all TS types. If you encounter a type which cannot be inferred, please raise an issue.
This means you should always have your decorators without explicit type
property.
decapi does reflection through typescript-rtti, so it can always infer a type directly from typescript without having to write them twice. This is what sets it apart, but there are other differences:
There is a much more popular library with the same goals. Differences:
@DuplexObjectType
and @DuplexField
Please if you enjoy decapi, go and star repo with the proposal-decorators . That's a way to show the TC39 members that you are using decorators and you want to have them in the language.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
Found 1/22 approved changesets -- score normalized to 0
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
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
86 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