Skip to content

Commit

Permalink
Add tests for @protocol annotation object notation
Browse files Browse the repository at this point in the history
  • Loading branch information
schwma committed Jul 26, 2024
1 parent 80a15ad commit 52b4b88
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 19 deletions.
40 changes: 21 additions & 19 deletions test/resources/annotations/srv/protocols.cds
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
service NotAnnotated {
context protocols {
entity A {
key id : UUID;
}
}

service NotAnnotated {
entity A as projection on protocols.A;
}

@protocol: 'none'
service AnnotatedWithAtProtocolNone {
entity A {
key id : UUID;
}
entity A as projection on protocols.A;
}

@protocol: 'odata'
service AnnotatedWithNonGraphQL {
entity A {
key id : UUID;
}
entity A as projection on protocols.A;
}

@graphql
service AnnotatedWithAtGraphQL {
entity A {
key id : UUID;
}
entity A as projection on protocols.A;
}

@protocol: 'graphql'
service AnnotatedWithAtProtocolString {
entity A {
key id : UUID;
}
entity A as projection on protocols.A;
}

@protocol: ['graphql']
service AnnotatedWithAtProtocolStringList {
entity A {
key id : UUID;
}
entity A as projection on protocols.A;
}

@protocol: [{kind: 'graphql'}]
service AnnotatedWithAtProtocolObjectList {
entity A {
key id : UUID;
}
entity A as projection on protocols.A;
}

@protocol: { graphql }
service AnnotatedWithAtProtocolObjectWithKey {
entity A as projection on protocols.A;
}

@protocol: { graphql: 'dummy' }
service AnnotatedWithAtProtocolObjectWithKeyAndValue {
entity A as projection on protocols.A;
}
72 changes: 72 additions & 0 deletions test/schemas/annotations.gql
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,74 @@ type AnnotatedWithAtProtocolObjectList_input {
A: AnnotatedWithAtProtocolObjectList_A_input
}

type AnnotatedWithAtProtocolObjectWithKey {
A(filter: [AnnotatedWithAtProtocolObjectWithKey_A_filter], orderBy: [AnnotatedWithAtProtocolObjectWithKey_A_orderBy], skip: Int, top: Int): AnnotatedWithAtProtocolObjectWithKey_A_connection
}

type AnnotatedWithAtProtocolObjectWithKeyAndValue {
A(filter: [AnnotatedWithAtProtocolObjectWithKeyAndValue_A_filter], orderBy: [AnnotatedWithAtProtocolObjectWithKeyAndValue_A_orderBy], skip: Int, top: Int): AnnotatedWithAtProtocolObjectWithKeyAndValue_A_connection
}

type AnnotatedWithAtProtocolObjectWithKeyAndValue_A {
id: ID
}

input AnnotatedWithAtProtocolObjectWithKeyAndValue_A_C {
id: ID
}

type AnnotatedWithAtProtocolObjectWithKeyAndValue_A_connection {
nodes: [AnnotatedWithAtProtocolObjectWithKeyAndValue_A]
totalCount: Int
}

input AnnotatedWithAtProtocolObjectWithKeyAndValue_A_filter {
id: [ID_filter]
}

type AnnotatedWithAtProtocolObjectWithKeyAndValue_A_input {
create(input: [AnnotatedWithAtProtocolObjectWithKeyAndValue_A_C]!): [AnnotatedWithAtProtocolObjectWithKeyAndValue_A]
delete(filter: [AnnotatedWithAtProtocolObjectWithKeyAndValue_A_filter]!): Int
}

input AnnotatedWithAtProtocolObjectWithKeyAndValue_A_orderBy {
id: SortDirection
}

type AnnotatedWithAtProtocolObjectWithKeyAndValue_input {
A: AnnotatedWithAtProtocolObjectWithKeyAndValue_A_input
}

type AnnotatedWithAtProtocolObjectWithKey_A {
id: ID
}

input AnnotatedWithAtProtocolObjectWithKey_A_C {
id: ID
}

type AnnotatedWithAtProtocolObjectWithKey_A_connection {
nodes: [AnnotatedWithAtProtocolObjectWithKey_A]
totalCount: Int
}

input AnnotatedWithAtProtocolObjectWithKey_A_filter {
id: [ID_filter]
}

type AnnotatedWithAtProtocolObjectWithKey_A_input {
create(input: [AnnotatedWithAtProtocolObjectWithKey_A_C]!): [AnnotatedWithAtProtocolObjectWithKey_A]
delete(filter: [AnnotatedWithAtProtocolObjectWithKey_A_filter]!): Int
}

input AnnotatedWithAtProtocolObjectWithKey_A_orderBy {
id: SortDirection
}

type AnnotatedWithAtProtocolObjectWithKey_input {
A: AnnotatedWithAtProtocolObjectWithKey_A_input
}

type AnnotatedWithAtProtocolString {
A(filter: [AnnotatedWithAtProtocolString_A_filter], orderBy: [AnnotatedWithAtProtocolString_A_orderBy], skip: Int, top: Int): AnnotatedWithAtProtocolString_A_connection
}
Expand Down Expand Up @@ -147,13 +215,17 @@ input ID_filter {
type Mutation {
AnnotatedWithAtGraphQL: AnnotatedWithAtGraphQL_input
AnnotatedWithAtProtocolObjectList: AnnotatedWithAtProtocolObjectList_input
AnnotatedWithAtProtocolObjectWithKey: AnnotatedWithAtProtocolObjectWithKey_input
AnnotatedWithAtProtocolObjectWithKeyAndValue: AnnotatedWithAtProtocolObjectWithKeyAndValue_input
AnnotatedWithAtProtocolString: AnnotatedWithAtProtocolString_input
AnnotatedWithAtProtocolStringList: AnnotatedWithAtProtocolStringList_input
}

type Query {
AnnotatedWithAtGraphQL: AnnotatedWithAtGraphQL
AnnotatedWithAtProtocolObjectList: AnnotatedWithAtProtocolObjectList
AnnotatedWithAtProtocolObjectWithKey: AnnotatedWithAtProtocolObjectWithKey
AnnotatedWithAtProtocolObjectWithKeyAndValue: AnnotatedWithAtProtocolObjectWithKeyAndValue
AnnotatedWithAtProtocolString: AnnotatedWithAtProtocolString
AnnotatedWithAtProtocolStringList: AnnotatedWithAtProtocolStringList
}
Expand Down
32 changes: 32 additions & 0 deletions test/tests/annotations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,37 @@ describe('graphql - annotations', () => {
const response = await POST(path, { query })
expect(response.data).not.toHaveProperty('errors')
})

test('service annotated with "@protocol: { graphql }" is served at configured path', async () => {
const query = gql`
{
AnnotatedWithAtProtocolObjectWithKey {
A {
nodes {
id
}
}
}
}
`
const response = await POST(path, { query })
expect(response.data).not.toHaveProperty('errors')
})

test('service annotated with "@protocol: { graphql: \'dummy\' }" is served at configured path', async () => {
const query = gql`
{
AnnotatedWithAtProtocolObjectWithKeyAndValue {
A {
nodes {
id
}
}
}
}
`
const response = await POST(path, { query })
expect(response.data).not.toHaveProperty('errors')
})
})
})

0 comments on commit 52b4b88

Please sign in to comment.