Replies: 1 comment
-
Hi @mingdengy, I'm not sure what's not working for you. It seems to work for me. Can you please try again with If the problem persists, please explain it in detail and provide input, expected output and actual output. Thanks |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using graphql2rest following the example. These are my codes.
const app = express()
await graphql2rest.generateGqlQueryFiles(schema, '/app/gqlFilesFolder')
const restRouter = graphql2rest.init(schema, execute, {
apiPrefix: '/api',
gqlGeneratorOutputFolder: '/app/gqlFilesFolder/',
manifestFile: '/app/manifest.json',
})
app.use('/api', restRouter)
await server.start()
server.applyMiddleware({ app }) // Apollo server
In execute function, I fetch graphql through remote server:
async function execute(args: GraphQLArgs): Promise {
const PORT = 8000
const url =
http://localhost:${PORT}/graphql
const headers = {
'content-type': 'application/json',
}
const graphqlQuery = {
operationName: args.operationName,
query: args.source,
variables: args.variableValues,
}
const options = {
method: 'POST',
headers,
body: JSON.stringify(graphqlQuery),
}
const response = await fetch(url, options)
const data = await response.json()
return data
}
The routes of RESTAPI and manifestFile are correct. They match.
But this execute function can not be called when I sending RESTAPI request.
Looks like restRouter can not be called in express.
The software dependencies are:
"express": "^4.18.1",
"graphql": "^15.8.0",
"graphql2rest": "^0.6.4"
Does anyone know why? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions