![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@hedviginsurance/graphql-schema-typescript
Advanced tools
Generate TypeScript from GraphQL's schema type definitions
This project is inspired by Apollo-codegen. Currently apollo-codegen only generate TypeScripts for GraphQL Client. The shape of the generated type is based on the client's query strings.
This module aim to do the Server counterpart: from a Schema Definition, generate the types to make it type-safed when developing GraphQL server (mainly resolvers)
import { generateTypeScriptTypes } from 'graphql-schema-typescript';
generateTypeScriptTypes(schema, outputPath, options)
.then(() => {
console.log('DONE');
process.exit(0);
})
.catch(err =>{
console.error(err);
process.exit(1);
});
You can then bootstrap this script on your dev server, or use something like ts-node to execute it directly
schema
: your graphql schemaoutputPath
: where the types is generatedoptions
: see GenerateTypescriptOptionsgraphql-schema-typescript generate-ts --help
for more detailsThe file generated will have some types that can make it type-safed when writing resolver:
any
, but could be overwritten in your codeFor example, if you schema is like this:
schema {
query: RootQuery
}
type RootQuery {
Users(input: UserFilter): [User!]!
# ... some more fields here
}
input UserFilter {
username: [String]
}
type User {
firstName: String!
# ... some more fields here
}
Then the tools will generate TypeScripts like this:
/**
* This interface define the shape of your resolver
* Note that this type is designed to be compatible with graphql-tools resolvers
* However, you can still use other generated interfaces to make your resolver type-safed
*/
export interface GQLResolver {
RootQuery?: GQLRootQueryTypeResolver;
User?: GQLUserTypeResolver;
}
export interface GQLRootQueryTypeResolver {
Users?: RootQueryToUsersResolver;
}
export interface RootQueryToUsersArgs {
Users?: GQLUserFilter;
}
export interface RootQueryToUsersResolver<TParent = any, TResult = any> {
(parent: TParent, args: RootQueryToUsersArgs, context: any, info: GraphQLResolveInfo): TResult;
}
In this example, if you are not using graphql-tools,
you can still use RootQueryToUsersResolver
type to make your args type safed.
In version 1.2.2, a strategy for generating default TParent and TResult has been implemented
by setting smartTParent
and smartTResult
options to true.
If both options are set to true, the resolver will be generated as follow:
// smartTParent: true
// smartTResult: true
// TParent is undefined because it uses the value of 'rootValueType' in options
export interface RootQueryToUsersResolver<TParent = undefined, TResult = Array<GQLUser> {
(parent: TParent, args: RootQueryToUsersArgs, context: any, info: GraphQLResolveInfo): TResult;
}
However, since RootQueryToUsersResolver
usually will be asynchronous operation,
the default TResult would not be too helpful, as developers would most likely overwrite it to Promise<Array<GQLUser>>
. Therefore, another option , asyncResult
, was implemented. This option
basically allow resolver to return promises
// smartTParent: true
// smartTResult: true
// asyncResult: true
export interface RootQueryToUsersResolver<TParent = undefined, TResult = Array<GQLUser> {
(parent: TParent, args: RootQueryToUsersArgs, context: any, info: GraphQLResolveInfo): Promise<TResult> | TResult; // the different is here
}
v1.2.2:
v1.2.1:
v1.2.0:
v1.1.0:
v1.0.6:
v1.0.4:
v1.0.2:
GQL_
to GQL
FAQs
Generate TypeScript from GraphQL's schema type definitions
The npm package @hedviginsurance/graphql-schema-typescript receives a total of 2 weekly downloads. As such, @hedviginsurance/graphql-schema-typescript popularity was classified as not popular.
We found that @hedviginsurance/graphql-schema-typescript demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
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.