Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL query typing #26

Open
raffazizzi opened this issue Jul 31, 2024 · 2 comments
Open

GraphQL query typing #26

raffazizzi opened this issue Jul 31, 2024 · 2 comments
Assignees

Comments

@raffazizzi
Copy link
Member

raffazizzi commented Jul 31, 2024

Types are currently automatically generated from graphql queries. This is very helpful, but it also creates types with properties that are more often than not nullable. This makes for awkward coding and makes it challenging to extend types. What can we do to make this more useful?

Nullable types

It makes sense for the properties to be nullable because they could be null even though we know from the airtable data that this won't be the case for the vast majority of the fields getting indexed.

Here are a couple possible options:

  • Investigate if it's possible to tighten the GraphQL schema so that fields are more predictable and so that errors can be returned on indexing the data if it doesn't match the expected data type.
  • Edit the generated types to better match the expected data. We shouldn't modify the AirTable bases and columns often, if at all, so this isn't too bad; but changes, however rare, will need to be introduced manually to the types.
  • Possibly a combination of the two solutions above.

Extending types

Currently the main reason for extending types is reconciling data across multiple fields/columns. For example information about event speakers (in column A) and speaker's affiliations (in column B).

Extending types is bothersome for a few reasons:

  • the types are deeply nested and typically nullable, which makes for very awkward extensions.
  • some subtypes are seemingly repeated but slightly different depending on the query, for example some images include the filepath others don't etc. This is because queries are tailored to their use in the component, which is the right thing to do. This can't really be optimized without moving away from automatically generated types IMO.
  • it's verbose and really clogs the code. But they can be moved to a separate file.

It would seem smart to try and prevent the need for extending types at the source, that is, in the AirTable data model. For example, it should be possible to get the speaker data already containing its affiliation, but which affiliation should be shown depends on the event, which complicates things. Perhaps we can review approaches with @ssapienza

@raffazizzi
Copy link
Member Author

ReadOnly types

All types are readonly by default as well. This makes it awkward to make adjustments to the query results, like filtering, deduping, sorting. While it makes sense to not modify the data, typing is still necessary for derived data structures (e.g the result of map, filter, or reduce. It's possible to create mutable versions of the types, but it seems that the extra code / effort brings little advantage in this case?

@ssapienza
Copy link
Contributor

Admittedly I think I'm having trouble understanding the starting point of this issue. By 'types,' do you mean the 16 records in the Types table in the Airtable base (Sponsored Project, Event, Workshop, etc)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants