question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support schema extension for GraphQL and REST data sources

See original GitHub issue

Context

Consider the following. We’re storing image metadata in our Postgres database using the PostGIS extension. Hasura supports PostGIS natively and creates a custom GraphQL scalar called geography to store the GPS coordinates. The value of this type is a GeoJSON. See https://hasura.io/docs/latest/schema/postgres/postgresql-types/#geography

We use Hasura as a backend for WunderGraph. Using the schema generated by WunderGraph, suppose I now try to query an image, e.g.

query GetImages {
  hasura_images {
    id
    location
  }
}

where location has geography type. Then WunderGraph would complain that returning location field in the response has incorrect type:

ERROR ResolveGraphQLResponse for query failed {"component": "@wundergraph/node", "error": "invalid value type 'object' for path /data/hasura_images/1/location, expecting string, got: {\"type\":\"Point\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"urn:ogc:def:crs:EPSG::4326\"}},\"coordinates\":[-0.136667,50.818889]}. You can fix this by configuring this field as Int/Float Scalar"}

This kinda makes sense as Hasura returns a GeoJSON object for location but WunderGraph can’t know that from introspection alone. The generated wundergraph.api.schema.graphql simply has:

scalar hasura_geography

So it seems we want to override the geography type generated by WunderGraph.

Feature Request

It seems that this is what we want: https://docs.wundergraph.com/docs/guides/extend-json-fields-with-more-specific-types

But currently, it’s only exposed to database sources.

It would be great if we can also extend GraphQL schemas from GraphQL sources (and maybe REST as well).

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
OLingardcommented, Nov 18, 2022

Hi @Slickstef11, sorry had a busy week! I’ve added a ticket to our backlog which I’ll pick up next week to look at this

0reactions
OLingardcommented, Dec 9, 2022

Hi @jensneuse, I’ve started the change in the Wundergraph codebase. You can find the current state here: https://github.com/wundergraph/wundergraph/compare/main...OLingard:wundergraph-test:FEAT/argument-replacements?expand=1. I thought the current state would be sufficient to fix the bug with the customIntScalar however, there seems to be a hidden issue. Unfortunately with my inexperience with the codebase I know that finding this bug would take me an unnecessarily long amount of time to find and fix. This combined with a pile up of work I’ve got on my plate means it could be quicker for all if you please could take a look and see if you can find the issue? Happy to work with you on it or just look at the changes once you’ve made them. Apologies for dropping this on you. Let me know your thoughts!

The link doesn’t seem to work. Can you update it?

The PR above contains the changes!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connecting to data sources | Full-Stack Quickstart
In this section, we'll extend DataSource to connect both a REST API and a SQL database ... Our schema also supports fetching an...
Read more >
Wrapping a REST API in GraphQL
We're going to create a GraphQL schema – a type system that describes your universe of data – that wraps calls to your...
Read more >
Extending types For Data Modelling in GraphQL | StepZen blog
This way, you can better organize your data from different sources. Let's explore how type extensions help with data modeling in GraphQL.
Read more >
Creating a GraphQL API while utilizing your REST API
Using an existing REST API we'll learn how to create a GraphQL API around our existing services instead of a complete rewrite of...
Read more >
Hasura for existing GraphQL and REST APIs: An Architect Guide
Hasura supports adding custom GraphQL servers via Remote Schemas. You need to plug your GraphQL endpoint along with the relevant auth headers ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found