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

[Stitching] Issues with enums #836

Closed
orta opened this issue Nov 27, 2017 · 6 comments
Closed

[Stitching] Issues with enums #836

orta opened this issue Nov 27, 2017 · 6 comments

Comments

@orta
Copy link
Contributor

orta commented Nov 27, 2017

From Slack

So, take this query

Causes issues like:

  "errors": [
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_DARK"
    },
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_LIGHT"
    },
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_DARK"
    },
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_DARK"
    },
    {
      "message": "Expected a value of type \"HomePageHeroUnitMode\" but received: LEFT_LIGHT"
    }
  ],

A quick look inside the enum shows they're defined as:

const HomePageHeroUnitType = new GraphQLObjectType({
  name: "HomePageHeroUnit",
  fields: {
    ...GravityIDFields,
    cached,
    mode: {
      type: new GraphQLEnumType({
        name: "HomePageHeroUnitMode",
        values: {
          LEFT_DARK: {
            value: "left white",
          },
          LEFT_LIGHT: {
            value: "left black",
          },
          CENTERED_DARK: {
            value: "center white",
          },
          CENTERED_LIGHT: {
            value: "center black",
          },
          RIGHT_DARK: {
            value: "right white",
          },
          RIGHT_LIGHT: {
            value: "right black",
          },
        },
      }),
      resolve: ({ type, menu_color_class }) => {
        return type.toLowerCase() + " " + menu_color_class.toLowerCase()
      },
    },

it looks like in turning on stitching, the value being passed into the completeLeafValue is the actual enum name LEFT_DARK not the value left white (sidenote: they're backwards?)

@orta
Copy link
Contributor Author

orta commented Nov 27, 2017

Possibly - ardatan/graphql-tools#363

@orta
Copy link
Contributor Author

orta commented Nov 28, 2017

Doesn't look like this fixes it.

Going to look at the merged resolvers, to verify that the resolvers in metaphysics' code are correct. This tells us whether it's on the way in, or on the way back.

If it's on the way back then look at potential verification passes inside the schema checks

@orta
Copy link
Contributor Author

orta commented Nov 28, 2017

Looks like it's doing two sets of "resolves" or verification steps, the results of the first one are put into the second one. So the enum "complete" function will mutate the results (from "left white" to "LEFT_DARK") and on the second check you have the name instead of the value

screen shot 2017-11-28 at 4 01 42 pm

I'd imagine the two sets of completions comes from first one being in "our" API, and the latter one coming from the merged schema "above".

Left = stitched

@orta
Copy link
Contributor Author

orta commented Jan 11, 2018

I chatted privately with @freiksenet about this back in november - his recommendation was to try treating Metaphysics as an external API also (so that stitching doesn't use the real resolvers initially)

So more like this

export function createConvectionLink() {
const httpLink = createHttpLink({
fetch,
uri: `${process.env.CONVECTION_API_BASE}/graphql`,
})
const middlewareLink = new ApolloLink((operation, forward) => forward(operation))
const authMiddleware = setContext((_request, context) => {
const locals = context.graphqlContext && context.graphqlContext.res.locals
const tokenLoader = locals && locals.dataLoaders.convectionTokenLoader
const headers = { ...(locals && requestIDHeaders(locals.requestIDs)) }
// If a token loader exists for Convection (i.e. this is an authenticated request), use that token to make
// authenticated requests to Convection.
if (tokenLoader) {
return tokenLoader().then(({ token }) => ({
headers: Object.assign(headers, { Authorization: `Bearer ${token}` }),
}))
}
// Otherwise use no authentication, which is also meant for fetching the service’s (public) schema.
return { headers }
})
return middlewareLink.concat(authMiddleware).concat(httpLink)
}

Instead of

import localSchema from "../schema"

return _mergeSchemas({
schemas: [localSchema, convectionSchema, linkTypeDefs],

@orta
Copy link
Contributor Author

orta commented Feb 5, 2018

unblocked by ardatan/graphql-tools#613

@orta
Copy link
Contributor Author

orta commented May 1, 2018

Fixed 👍

@orta orta closed this as completed May 1, 2018
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

1 participant