Skip to content

Commit

Permalink
fix(wabe): array in object
Browse files Browse the repository at this point in the history
  • Loading branch information
coratgerl committed Jan 27, 2025
1 parent e6f9564 commit 80493c8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
41 changes: 41 additions & 0 deletions packages/wabe/src/graphql/GraphQLSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,47 @@ describe('GraphqlSchema', () => {
})
})

it('should be able to create an array in an object', async () => {
const { wabe } = await createWabe({
classes: [
{
name: 'TestClass',
fields: {
field1: {
type: 'Array',
typeValue: 'Object',
object: {
name: 'SubOject',
fields: {
field2: {
type: 'Array',
typeValue: 'String',
required: true,
requiredValue: false,
},
field3: { type: 'Int' },
},
},
},
},
},
],
})

expect(
getTypeFromGraphQLSchema({
schema: wabe.config.graphqlSchema || ({} as any),
type: 'Type',
name: 'TestClassSubOject',
}).input,
).toEqual({
field2: '[String]!',
field3: 'Int',
})

await wabe.close()
})

// It is usefull when we have the permission to create but not to read the data
// We should be able to create a new object without return any data
// Just use the "ok" field
Expand Down
21 changes: 21 additions & 0 deletions packages/wabe/src/graphql/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ export const GraphqlParser: GraphqlParserConstructor =
}
}

if (
currentField.typeValue &&
// @ts-expect-error
templateScalarType[currentField.typeValue]
) {
const graphqlType = getGraphqlType({
type: currentField.type,
// @ts-expect-error
typeValue: currentField.typeValue,
isWhereType: false,
requiredValue: currentField.requiredValue,
})

acc[key] = {
type:
currentField.required && !forceRequiredToFalse
? new GraphQLNonNull(graphqlType)
: graphqlType,
}
}

return acc
}

Expand Down
7 changes: 4 additions & 3 deletions packages/wabe/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface WabeConfig<T extends WabeTypes> {
hostname?: string
security?: SecurityConfig
schema?: SchemaInterface<T>
graphqlSchema?: GraphQLSchema
database: DatabaseConfig
codegen?:
| {
Expand Down Expand Up @@ -219,7 +220,7 @@ export class Wabe<T extends WabeTypes> {

const types = graphqlSchema.createSchema()

const schema = new GraphQLSchema({
this.config.graphqlSchema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: types.queries,
Expand All @@ -241,7 +242,7 @@ export class Wabe<T extends WabeTypes> {
await generateCodegen({
path: this.config.codegen.path,
schema: wabeSchema.schema,
graphqlSchema: schema,
graphqlSchema: this.config.graphqlSchema,
})

// If we just want codegen we exit before server created.
Expand Down Expand Up @@ -323,7 +324,7 @@ export class Wabe<T extends WabeTypes> {

this.server.usePlugin(
WobeGraphqlYogaPlugin({
schema,
schema: this.config.graphqlSchema,
maskedErrors: false,
graphqlEndpoint: '/graphql',
plugins: this.config.isProduction ? [useDisableIntrospection()] : [],
Expand Down

0 comments on commit 80493c8

Please sign in to comment.