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

How can use SOFA with Conditional Schema? #1357

Closed
ggagosh opened this issue Jun 16, 2023 · 7 comments
Closed

How can use SOFA with Conditional Schema? #1357

ggagosh opened this issue Jun 16, 2023 · 7 comments

Comments

@ggagosh
Copy link

ggagosh commented Jun 16, 2023

Hey, Is there any way to use SOFA with Conditional Schema?

@ardatan
Copy link
Collaborator

ardatan commented Jun 16, 2023

You can use Yoga as in the example then add SOFA plugin :)
https://the-guild.dev/graphql/yoga-server/docs/features/sofa-api

@ggagosh
Copy link
Author

ggagosh commented Jun 16, 2023

You can use Yoga as in the example then add SOFA plugin :) https://the-guild.dev/graphql/yoga-server/docs/features/sofa-api

Hey, there is no documentation on how to use this plugin with Conditional Schema. Based on the request.

@ardatan
Copy link
Collaborator

ardatan commented Jun 16, 2023

Maybe I am missing something here. Conditional schema is the configuration for Yoga. You configure the schema as in that section you shared then add the plugin as in the one I sent.

@ggagosh
Copy link
Author

ggagosh commented Jun 16, 2023

Ok, you are right, I just create an issue for the wrong repo 😞 It's Yoga's error. I will close the issue. Thanks.

@ggagosh ggagosh closed this as completed Jun 16, 2023
@ardatan
Copy link
Collaborator

ardatan commented Jun 16, 2023

Is there any error you're getting?
You basically need to take this;
image
And add the plugin like this;
image

@ggagosh
Copy link
Author

ggagosh commented Jun 16, 2023

This is the minimal reproduction, You can check logs. I also create an issue for Yoga.

Without a Sofa plugin, it works fine.

@devhoangkien
Copy link

i have a similar problem.: https://the-guild.dev/graphql/yoga-server/docs/features/sofa-api

const yoga = createYoga({
  landingPage: true,
  schema: createSchema({ typeDefs, resolvers }),
  plugins: [
    useSofa({
      basePath: '/api',
      swaggerUI: {
        endpoint: '/swagger'
      },
      openAPI: {
        info: {
          title: 'Bun Server REST API',
          version: '1.0.0',
          description: 'Bun Server REST API'

        }
      },
    })
  ]
},)

I call rest api on swagger successfully. but when calling on graphql, the following error is reported. Haven't called the server yet

{
  "errors": [
    {
      "message": "Failed to fetch",
      "extensions": {
        "requestBody": {
          "query": "query MyQuery {\n  getPost(id: 1) {\n    content\n    title\n    id\n  }\n}",
          "operationName": "MyQuery"
        },
        "responseDetails": {}
      }
    }
  ]
}

but when I remove the plugin, graphql works normally

const yoga = createYoga({
  landingPage: true,
  schema: createSchema({ typeDefs, resolvers }),
  // plugins: [
  //   useSofa({
  //     basePath: '/api',
  //     swaggerUI: {
  //       endpoint: '/swagger'
  //     },
  //     openAPI: {
  //       info: {
  //         title: 'Bun Server REST API',
  //         version: '1.0.0',
  //         description: 'Bun Server REST API'

  //       }
  //     },
  //   })
  // ]
},)
{
  "data": {
    "getPost": null
  }
}

i use bun 1.04

import { createSchema, createYoga } from 'graphql-yoga'
import { BunToText } from './utils/text-logs';
import { readFileSync } from 'node:fs'
import { resolvers } from './modules/app.resolvers';
import { useSofa } from '@graphql-yoga/plugin-sofa'


const typeDefs = readFileSync('./schema.graphql', 'utf8')

const yoga = createYoga({
  landingPage: true,
  schema: createSchema({ typeDefs, resolvers }),
  // plugins: [
  //   useSofa({
  //     basePath: '/api',
  //     swaggerUI: {
  //       endpoint: '/swagger'
  //     },
  //     openAPI: {
  //       info: {
  //         title: 'Bun Server REST API',
  //         version: '1.0.0',
  //         description: 'Bun Server REST API'

  //       }
  //     },
  //   })
  // ]
},)

const server = Bun.serve({
  fetch: yoga.fetch.bind(yoga),
  port: Bun.env.PORT || 8888,
  hostname: Bun.env.HOST || 'localhost',
  development: Bun.env.NODE_ENV !== 'production' ? true : false
});
console.info(BunToText)
console.info(
  `Server is running on ${new URL(
    yoga.graphqlEndpoint,
    `http://${server.hostname}:${server.port}`
  )}`
)

link github source: https://github.com/devhoangkien/bun-server-template.git

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