Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@threads/apollo-resolver-types
Advanced tools
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
We found that @threads/apollo-resolver-types demonstrated a not healthy version release cadence and project activity because the last version was released 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.
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.