![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
graphql-typewriter
Advanced tools
Easy TypeScript interfaces for your GraphQL server
npm install -g graphql-typewriter
Usage: graphql-typewriter [options]
Convert all .graphqls schema-files in the current directory tree into typescript
interfaces that can be used to implement a graphql-root for this schema.
Options:
-V, --version output the version number
-x, --exclude <dirs> a list of directories to exclude
--dont-save-same-file do not save a file if the contents has not changed. This read each target file prior to loading
-h, --help output usage information
graphql-typewriter
is assumed to be run in the root folder of a npm-project.
It finds all .graphqls files recursively and adds a .graphqls.ts file next each file
(excluding the node_modules
-folder).
The source GraphQL-schema example.graphqls
that looks like
# The base query
type Query {
# Retrieve a person by name
person(name:String): Person
}
# A type describing a person
type Person {
# The persons name
name: String!
# The persons age in years
age: Int!
# Friendship relations to other persons
friends: [Person!]
}
will be converted into the following example.graphqls.types.ts
:
/* tslint:disable */
export namespace schema {
export type GraphqlField<Args, Result, Ctx> = Result | Promise<Result> |
((args: Args, context: Ctx) => Result | Promise<Result>)
/**
* The base query
*/
export interface Query<Ctx> {
/**
* Retrieve a person by name
*/
person?: GraphqlField<{name: string}, Person<Ctx> | undefined, Ctx>
}
/**
* A type describing a person
*/
export interface Person<Ctx> {
/**
* The persons name
*/
name: GraphqlField<{}, string, Ctx>
/**
* The persons age in years
*/
age: GraphqlField<{}, number, Ctx>
/**
* Friendship relations to other persons
*/
friends?: GraphqlField<{}, Person<Ctx>[] | undefined, Ctx>
}
export const defaultResolvers = {
}
}
Note that all the field (non-argument) types can either be
Person
),Promise<Person>
),(): Person
), or(): Promise<Person>
)For fields with arguments, only the latter two apply.
With this interface, you can write the following program (example-usage.ts
):
import { graphql, buildSchema } from 'graphql'
import { schema } from './graphql/schema/example.graphqls.types'
import * as fs from 'fs'
type Context = {
year: number
}
// Implement the generated interface
class Root implements schema.Query<Context> {
person (args: {name: string}) {
return new Person(args.name, 1981)
}
}
class Person implements schema.Person<Context> {
name: string
yearOfBirth: number
constructor (name: string, yearOfBirth: number) {
this.name = name
this.yearOfBirth = yearOfBirth
}
age (_, context: Context) {
return context.year - this.yearOfBirth
}
async friends (): Promise<Person[]> {
return Promise.resolve([
new Person(this.name + "'s first friend", this.yearOfBirth - 1),
new Person(this.name + "'s second friend", this.yearOfBirth - 2)
])
}
}
// Run a query
graphql(
buildSchema(fs.readFileSync('graphql/schema/example.graphqls', {encoding: 'utf-8'})),
'{ person(name:"Joye") { name age friends { name age } }}',
new Root(),
{year: 2017}
).then((result) => console.log(JSON.stringify(result, null, 2)))
The program uses the interface to build an root-implementation that can be validate by Typescript (Promise validation works with TypeScript 2.1 onwards).
The output of this program is
{
"data": {
"person": {
"name": "Joye",
"age": 36,
"friends": [
{
"name": "Joye's first friend",
"age": 37
},
{
"name": "Joye's second friend",
"age": 38
}
]
}
}
}
graphql-typewriter
is published under the MIT-license.
See LICENSE.md for details.
For release notes, see CHANGELOG.md
See CONTRIBUTING.md.
Version 1.0.0 (Wed, 16 Aug 2017 19:23:53 GMT)
FAQs
Easy TypeScript interfaces for your GraphQL server
The npm package graphql-typewriter receives a total of 1 weekly downloads. As such, graphql-typewriter popularity was classified as not popular.
We found that graphql-typewriter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.