Comparing version 0.0.7 to 0.0.8
@@ -65,2 +65,38 @@ import { GraphQLObjectType, GraphQLString, GraphQLSchema } from 'graphql'; | ||
}); | ||
it('should work when schema registered with async resolve function', async () => { | ||
const app = new EdgeQL(); | ||
const queryType = new GraphQLObjectType({ | ||
name: 'Query', | ||
fields: { | ||
hello: { | ||
type: GraphQLString, | ||
resolve: async () => { | ||
return new Promise((res) => { | ||
res('world'); | ||
}); | ||
}, | ||
}, | ||
}, | ||
}); | ||
app.register(new GraphQLSchema({ query: queryType })); | ||
const req = new Request('http://localhost', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: 'query H { hello }', | ||
variables: {}, | ||
operationName: 'H', | ||
extensions: {}, | ||
}), | ||
}); | ||
const res = await app.fetch(req); | ||
expect(res.status).toBe(200); | ||
expect(await res.json()).toEqual({ | ||
data: { | ||
hello: 'world', | ||
}, | ||
}); | ||
}); | ||
it('should work when schema string registered', async () => { | ||
@@ -193,2 +229,33 @@ const app = new EdgeQL(); | ||
}); | ||
it('should be able to get the environment variable inside handler', async () => { | ||
const app = new EdgeQL(); | ||
const schema = ` | ||
type Query { | ||
hello: String | ||
} | ||
`; | ||
app.register(schema, (parent, args, ctx) => { | ||
return `${ctx.env.db} world`; | ||
}); | ||
const req = new Request('http://localhost', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: 'query H { hello }', | ||
variables: {}, | ||
operationName: 'H', | ||
extensions: {}, | ||
}), | ||
}); | ||
const db = 'hello-db'; | ||
const res = await app.fetch(req, { db }); | ||
expect(res.status).toBe(200); | ||
expect(await res.json()).toEqual({ | ||
data: { | ||
hello: `${db} world`, | ||
}, | ||
}); | ||
}); | ||
}); |
@@ -17,7 +17,2 @@ import type { Context } from './context'; | ||
} | ||
export type Bindings = Record<string, any>; | ||
export type Variables = Record<string, any>; | ||
export type Environment = { | ||
Bindings: Bindings; | ||
Variables: Variables; | ||
}; | ||
export type Environment = Record<string, any>; |
{ | ||
"name": "edgeql", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35052
1016