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

fix(executor): handle resolveType correctly for v15 #6280

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Jun 19, 2024

Fixes #6279

Since the executor is version agnostic, it should respect the schemas created with older versions.

So if a type resolver returns a type instead of type name which is required since graphql@16, the executor should handle it correctly.

See the following example:

// Assume that the following code is executed with `graphql@15`
import { execute } from '@graphql-tools/executor';

const BarType = new GraphQLObjectType({
  name: 'Bar',
  fields: {
    bar: {
      type: GraphQLString,
      resolve: () => 'bar'
    }
  }
});
const BazType = new GraphQLObjectType({
  name: 'Baz',
  fields: {
    baz: {
      type: GraphQLString,
      resolve: () => 'baz'
    }
  }
});
const BarBazType = new GraphQLUnionType({
  name: 'BarBaz',
  types: [BarType, BazType],
  // This is the resolver that returns the type instead of type name
  resolveType(obj) {
    if ('bar' in obj) {
      return BarType;
    }
    if ('baz' in obj) {
      return BazType;
    }
  }
});
const QueryType = new GraphQLObjectType({
  name: 'Query',
  fields: {
    barBaz: {
      type: BarBazType,
      resolve: () => ({ bar: 'bar' })
    }
  }
});
const schema = new GraphQLSchema({
  query: QueryType
});

const result = await execute({
  schema,
  document: parse(
    /* GraphQL */ `
      query {
        barBaz {
          ... on Bar {
            bar
          }
          ... on Baz {
            baz
          }
        }
      }
    `
  )
});

expect(result).toEqual({
  data: {
    barBaz: {
      bar: 'bar'
    }
  }
});

Copy link

changeset-bot bot commented Jun 19, 2024

🦋 Changeset detected

Latest commit: cd1ab96

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-tools/executor Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jun 19, 2024

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-tools/executor 1.2.7-alpha-20240619191149-cd1ab96503149b7ed7feaeae653872e1579a89ca npm ↗︎ unpkg ↗︎

Copy link
Contributor

✅ Benchmark Results

     ✓ no_errors
     ✓ expected_result

     checks.........................: 100.00% ✓ 332       ✗ 0  
     data_received..................: 39 MB   3.9 MB/s
     data_sent......................: 142 kB  14 kB/s
     http_req_blocked...............: avg=4.17µs  min=1.98µs   med=2.63µs   max=203.65µs p(90)=3.86µs   p(95)=4.26µs  
     http_req_connecting............: avg=827ns   min=0s       med=0s       max=137.28µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=56.26ms min=48.09ms  med=52.26ms  max=150.1ms  p(90)=61.98ms  p(95)=87.13ms 
       { expected_response:true }...: avg=56.26ms min=48.09ms  med=52.26ms  max=150.1ms  p(90)=61.98ms  p(95)=87.13ms 
     http_req_failed................: 0.00%   ✓ 0         ✗ 166
     http_req_receiving.............: avg=132.7µs min=109.74µs med=129.33µs max=252.84µs p(90)=147.61µs p(95)=154.35µs
     http_req_sending...............: avg=25.72µs min=17.68µs  med=23.8µs   max=116.8µs  p(90)=31µs     p(95)=35.06µs 
     http_req_tls_handshaking.......: avg=0s      min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=56.1ms  min=47.95ms  med=52.11ms  max=149.77ms p(90)=61.83ms  p(95)=86.97ms 
     http_reqs......................: 166     16.557178/s
     iteration_duration.............: avg=60.37ms min=51.57ms  med=56.31ms  max=153.93ms p(90)=66.45ms  p(95)=91.82ms 
     iterations.....................: 166     16.557178/s
     vus............................: 1       min=1       max=1
     vus_max........................: 1       min=1       max=1

Copy link
Contributor

💻 Website Preview

The latest changes are available as preview in: https://5f0a1ec5.graphql-tools.pages.dev

@ardatan ardatan merged commit 7dcd0af into master Jun 21, 2024
30 checks passed
@ardatan ardatan deleted the graphql-15-abstract branch June 21, 2024 21:30
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

Successfully merging this pull request may close these issues.

Update @graphql-tools/executor peer dependencies to exclude graphql v16
2 participants