Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@threads/apollo-resolver-types
Advanced tools
Readme
Strong typing for apollo resolvers
To setup a graphql server with strong types you will need the following:
ApolloResolverTypes
to mark any necessary resolvers as required.Since the type definitions for GraphQL can get pretty big, you might find TypeScript runs out of memory. This can usually be solved by replacing your
tsc
call withNODE_OPTIONS=\"--max-old-space-size=2048\" tsc
.
./src/graphql/ResolverTypes.ts
should look like:
import ApolloResolverTypes from '@threads/apollo-resolver-types';
import * as GeneratedTypes from './__generated__/types';
type ResolverTypes = ApolloResolverTypes<GeneratedTypes.Resolvers>;
export default ResolverTypes;
You can then refer to ResolverTypes['Query']['contactById']
to get the type of the contactById
resolver or ResolverTypes['Contact']['accounts']
to get the accounts
resolver on the Contact
object.
To generate the types from your schema, run: apollo-resolver-types src/graphql/codegen.yml
. If you've configured it as per the example, this will output two files in the src/graphql/__generated__
directory. For a full list of available config options, see https://graphql-code-generator.com/
apollo-resolver-types codegen-config.yml [options]
Options:
-w, --watch Watch for changes and execute generation automatically
Sometimes you might be unclear on why a given resolver is required. You might think it should be optional, but apollo-resolver-types says it's required. To resolve this you can try:
import * as GeneratedTypes from './__generated__/types';
import {DebugResolver} from '@threads/apollo-resolver-types';
type X = DebugResolver<GeneratedTypes.Resolvers['Contact'], 'accounts'>;
You can then hover over X and you should see something like:
type X = {
requiredValue: Account[];
implicitValue: undefined;
};
The requiredValue is the type defined in the GraphQL schema. The implicitValue is the value in TypeScript. If the implicitValue is assignable to the requiredValue, no resolver should be required. In the above example, undefined
cannot be assigned to Account[]
, so you will need a resolver for Contact.accounts
.
FAQs
Strong typing for apollo resolvers
The npm package @threads/apollo-resolver-types receives a total of 127 weekly downloads. As such, @threads/apollo-resolver-types popularity was classified as not popular.
We found that @threads/apollo-resolver-types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 19 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.