pothos-dev / apollo-hooks-codegen Goto Github PK
View Code? Open in Web Editor NEWA plugin for graphql-code-generator to create fully typed React Hooks from GraphQL queries, mutations and subscriptions.
A plugin for graphql-code-generator to create fully typed React Hooks from GraphQL queries, mutations and subscriptions.
I've run into a few situations where conditionally executing a query would be very beneficial, for instance when one query returns the ID of the logged in user, and another query would then fetch some more user data based on that ID.
At the moment the (only?) way to do this is to create a component for the query and then conditionally render that. Implementing Apollo's skip
option could make this a lot easier ๐
Maybe some prior art here trojanowski/react-apollo-hooks#42
๐
I'm trying to use [email protected]
with GraphQL interfaces, is this supported? At the moment I'm getting an error about unhandled GraphQLOutputType in unwrap
with the following schema:
interface Document {
id: ID!
permalink: String!
}
type Verdict implements Document @hasScope(scope: ["read:verdict"]) {
id: ID!
permalink: String!
}
Logging the type shows it's complaining about Document
.
Thanks so much for this library, it's been incredibly helpful for the project I'm building. I was wondering if the following was supported:
schema:
type Mutation {
unionMethod(body: String): UnionType
}
type FieldError {
field: String
}
type Errors {
fieldErrors: [FieldError]
}
type MutationResponse {
ok: Boolean
}
union UnionType = Errors | MutationResponse
documents:
mutation unionMethod {
unionMethod(body: "test") {
...on Errors {
fieldErrors {
field
}
}
...on MutationResponse {
ok
}
}
}
Currently, this throws an exception TypeError: Cannot create property 'source' on string 'unhandled GraphQLOutputType in unwrap'
which appears to be coming from an unhandled case in https://github.com/bearbytes/apollo-hooks-codegen/blob/master/src/transform.ts#L381 .
Are there plans to support this use case, or suggestions for the best way to handle it moving forward? Happy to provide a PR if you have a sense of what we might need.
Thanks!
When using --noUnusedLocals
tsc option, there are two vars that fail for my build: ApolloQueryResult
and subscription
. (dependent on feature usage I'm sure).
I had to use the add
plugin for codegen to make my build pass like this:
src/graphql.tsx:
plugins:
- 'apollo-hooks-codegen'
- add: '/* Added to bypass noUnusedLocals tsconfig */ type Ditch = ApolloQueryResult<any>; const noop = (...args: Ditch | any) => void args; noop(subscription);'
This works but perhaps this lib could output the vars that are only needed/used to improve this experience.
Hey there,
I'm having an issue where the useQuery hook is only fetching data from the first query it executes upon a component mounting. In subsequent component mounts, the query doesn't refetch data with the new variables provided, rather it returns the data from the initial query. I.E. - a user is selected via userId and the useQuery hook fetches that user's userGroups. Groups are then displayed in a userCard. When a different user is chosen, the new user's userId is passed down, but the data that comes back from the useQuery hook is still the first user's userGroups, despite the new userId. Any ideas how I can fix this issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.