apollo-server-express#gql TypeScript Examples
The following examples show how to use
apollo-server-express#gql.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: entity.resolver.spec.ts From amplication with Apache License 2.0 | 6 votes |
FIND_MANY_PERMISSIONS_QUERY = gql`
query($entityId: String!) {
entity(where: { id: $entityId }) {
permissions {
id
entityVersionId
action
type
}
}
}
`
Example #2
Source File: federation.test.ts From graphql-schema-registry with MIT License | 6 votes |
describe('app/helpers/federation.js', () => {
it('schema validation supports directives', () => {
const typeDefs = gql`
directive @test on FIELD_DEFINITION
type Query {
user(id: ID!): User!
}
type User {
id: ID!
username: String! @test
}
`;
typeDefs.toString = () => {
return typeDefs.loc.source.body.toString();
};
const schema = {
name: 'test schema',
type_defs: typeDefs.toString(),
};
try {
const validatedSchema = composeAndValidateSchema([schema]);
assert.isNotNull(validatedSchema);
} catch (error) {
assert.fail(error.details);
}
});
});
Example #3
Source File: getUser.ts From fullstack-starterkit with MIT License | 6 votes |
getUser = gql`
query getUser($input: GetUserInput!) {
getUser(input: $input) {
user {
id
email
name
posts {
id
}
}
}
}
`
Example #4
Source File: index.ts From Next.js_GraphQL_Express_Apollo_Boilerplate with MIT License | 6 votes |
typeDefs = gql`
type Query {
users: [User!]!
user(userId: ID!): User!
login(email: String!, password: String!): AuthData!
}
type Mutation {
createUser(userInput: UserInput): AuthData!
updateUser(userId: ID!, updateUser: UpdateUser): User!
}
type Subscription {
userAdded: User
}
type User {
_id: ID!
email: String!
name: String!
password: String
createdAt: String!
updatedAt: String!
}
type AuthData {
userId: ID!
token: String!
tokenExpiration: Int!
}
input UserInput {
email: String!
name: String!
password: String!
}
input UpdateUser {
email: String
name: String
password: String
}
`
Example #5
Source File: workspace.resolver.spec.ts From amplication with Apache License 2.0 | 6 votes |
INVITE_USER_MUTATION = gql`
mutation($email: String!) {
inviteUser(data: { email: $email }) {
id
email
createdAt
updatedAt
}
}
`
Example #6
Source File: type-defs.ts From master-frontend-lemoncode with MIT License | 6 votes |
typeDefs = gql`
type Hotel {
id: ID!
type: String!
name: String!
address1: String!
city: String!
hotelRating: Float!
shortDescription: String!
thumbNailUrl: String!
tripAdvisorRating: Float!
tripAdvisorRatingUrl: String!
}
type Query {
hotels: [Hotel!]!
}
`
Example #7
Source File: entity.resolver.spec.ts From amplication with Apache License 2.0 | 6 votes |
GET_VERSION_PERMISSIONS_QUERY = gql`
query($entityId: String!) {
entity(where: { id: $entityId }) {
versions {
permissions {
id
entityVersionId
action
type
}
}
}
}
`
Example #8
Source File: index.ts From jmix-frontend with Apache License 2.0 | 6 votes |
export async function createServer(schemaPath: any, mockRest = true, allowInvalidCreds = true) {
let typeDefs
try {
typeDefs = await readFileSync(schemaPath).toString('utf-8');
} catch (ex) {
throw new Error(`Unable to read ${schemaPath}, please specify correct path to grapqhl schema file using --schema option`)
}
const expressApp = express();
const apolloServer = new ApolloServer({
typeDefs,
mocks,
resolvers: mockedResolvers(gql`${typeDefs}`),
mockEntireSchema: false
});
await apolloServer.start();
apolloServer.applyMiddleware({app: expressApp});
expressApp.use(express.urlencoded({extended: false}), express.json())
expressApp.use(createOauthRouter(allowInvalidCreds))
if (mockRest) {
expressApp.use(restRouter)
}
return {expressApp, apolloServer};
}
Example #9
Source File: type-defs.ts From master-frontend-lemoncode with MIT License | 6 votes |
typeDefs = gql`
type Hotel {
id: ID!
type: String!
name: String!
address1: String!
city: String!
hotelRating: Float!
shortDescription: String!
thumbNailUrl: String!
tripAdvisorRating: Float!
tripAdvisorRatingUrl: String!
}
type City {
id: ID!
name: String!
}
type Query {
hotels: [Hotel!]!
hotel(id: ID!): Hotel!
cities: [City!]!
}
input HotelInput {
id: ID!
name: String!
address1: String!
city: String!
hotelRating: Float!
shortDescription: String!
}
type Mutation {
saveHotel(hotel: HotelInput!): Boolean
deleteHotel(id: ID!): Boolean
}
`
Example #10
Source File: typeDefs.ts From Full-Stack-React-TypeScript-and-Node with MIT License | 6 votes |
typeDefs = gql`
type User {
id: ID!
username: String!
email: String
}
type Todo {
id: ID!
title: String!
description: String
}
type Query {
getUser(id: ID): User
getTodos: [Todo!]
}
type Mutation {
addTodo(title: String!, description: String): Todo
}
type Subscription {
newTodo: Todo!
}
`
Example #11
Source File: account.resolver.spec.ts From amplication with Apache License 2.0 | 6 votes |
UPDATE_ACCOUNT_MUTATION = gql`
mutation($data: UpdateAccountInput!) {
updateAccount(data: $data) {
id
createdAt
updatedAt
email
firstName
lastName
password
}
}
`
Example #12
Source File: typeDefs.ts From cloud-pricing-api with Apache License 2.0 | 5 votes |
typeDefs = gql`
type Price {
priceHash: String!
purchaseOption: String
unit: String!
USD: String!
${CURRENCY_CODES.map((code) => `${code}: String`).join('\n')}
effectiveDateStart: String
effectiveDateEnd: String
startUsageAmount: String
endUsageAmount: String
description: String
termLength: String
termPurchaseOption: String
termOfferingClass: String
}
type Product {
productHash: String!
vendorName: String!
service: String!
productFamily: String
region: String
sku: String!
attributes: [Attribute]
prices(filter: PriceFilter): [Price]
}
type Attribute {
key: String!
value: String
}
input AttributeFilter {
key: String!
value: String
value_regex: String
}
input ProductFilter {
vendorName: String
service: String
productFamily: String
region: String
sku: String
attributeFilters: [AttributeFilter]
}
input PriceFilter {
purchaseOption: String
unit: String
description: String
description_regex: String
startUsageAmount: String
endUsageAmount: String
termLength: String
termPurchaseOption: String
termOfferingClass: String
}
type Query {
products(filter: ProductFilter): [Product]
}
`
Example #13
Source File: build.resolver.spec.ts From amplication with Apache License 2.0 | 5 votes |
ARCHIVE_URI_QUERY = gql`
query($id: String!) {
build(where: { id: $id }) {
archiveURI
}
}
`
Example #14
Source File: typeDefs.ts From tinyhouse with MIT License | 5 votes |
typeDefs = gql`
type Listings {
total: Int!
result: [Listing!]!
}
enum ListingType {
APARTMENT
HOUSE
}
enum ListingsFilter {
PRICE_LOW_TO_HIGH
PRICE_HIGH_TO_LOW
}
type Listing {
id: ID!
title: String!
description: String!
image: String!
host: User!
type: ListingType!
address: String!
city: String!
bookings(limit: Int!, page: Int!): Bookings
bookingsIndex: String!
price: Int!
numOfGuests: Int!
}
type Bookings {
total: Int!
result: [Booking!]!
}
type Booking {
id: ID!
listing: Listing!
tenant: User!
checkIn: String!
checkOut: String!
}
type User {
id: ID!
name: String!
avatar: String!
contact: String!
hasWallet: Boolean!
income: Int
bookings(limit: Int!, page: Int!): Bookings
listings(limit: Int!, page: Int!): Listings!
}
type Viewer {
id: ID
token: String
avatar: String
hasWallet: Boolean
didRequest: Boolean!
}
input LogInInput {
code: String!
}
type Query {
authUrl: String!
user(id: ID!): User!
listing(id: ID!): Listing!
listings(filter: ListingsFilter!, limit: Int!, page: Int!): Listings!
}
type Mutation {
logIn(login: LogInInput): Viewer!
logOut: Viewer!
}
`
Example #15
Source File: graphql.ts From the-fake-backend with ISC License | 5 votes |
constructor(definitions: TemplateStringsArray | string) {
this.typeDefs = gql(definitions);
}
Example #16
Source File: typeDefs.ts From Full-Stack-React-TypeScript-and-Node with MIT License | 4 votes |
typeDefs = gql`
scalar Date
type EntityResult {
messages: [String!]
}
type User {
id: ID!
email: String!
userName: String!
password: String!
confirmed: Boolean!
isDisabled: Boolean!
threads: [Thread!]
threadItems: [ThreadItem!]
createdBy: String!
createdOn: Date!
lastModifiedBy: String!
lastModifiedOn: Date!
}
union UserResult = User | EntityResult
type Thread {
id: ID!
views: Int!
points: Int!
isDisabled: Boolean!
title: String!
body: String!
user: User!
threadItems: [ThreadItem!]
category: ThreadCategory!
createdBy: String!
createdOn: Date!
lastModifiedBy: String!
lastModifiedOn: Date!
}
union ThreadResult = Thread | EntityResult
type ThreadArray {
threads: [Thread!]
}
union ThreadArrayResult = ThreadArray | EntityResult
type ThreadItem {
id: ID!
views: Int!
points: Int!
isDisabled: Boolean!
body: String!
user: User!
thread: Thread!
createdBy: String!
createdOn: Date!
lastModifiedBy: String!
lastModifiedOn: Date!
}
union ThreadItemResult = ThreadItem | EntityResult
type ThreadItemArray {
threadItems: [ThreadItem!]
}
union ThreadItemArrayResult = ThreadItemArray | EntityResult
type ThreadCategory {
id: ID!
name: String!
description: String
threads: [Thread!]!
createdBy: String!
createdOn: Date!
lastModifiedBy: String!
lastModifiedOn: Date!
}
type ThreadPoint {
id: ID!
isDecrement: Boolean!
user: User!
thread: Thread!
createdBy: String!
createdOn: Date!
lastModifiedBy: String!
lastModifiedOn: Date!
}
type ThreadItemPoint {
id: ID!
isDecrement: Boolean!
user: User!
threadItem: ThreadItem!
createdBy: String!
createdOn: Date!
lastModifiedBy: String!
lastModifiedOn: Date!
}
type CategoryThread {
threadId: ID!
categoryId: ID!
categoryName: String!
title: String!
titleCreatedOn: Date!
}
type Query {
getThreadById(id: ID!): ThreadResult
getThreadsByCategoryId(categoryId: ID!): ThreadArrayResult!
getThreadsLatest: ThreadArrayResult!
getThreadItemByThreadId(threadId: ID!): ThreadItemArrayResult!
getAllCategories: [ThreadCategory!]
me: UserResult!
getTopCategoryThread: [CategoryThread!]
}
type Mutation {
createThread(
userId: ID!
categoryId: ID!
title: String!
body: String!
): EntityResult
createThreadItem(userId: ID!, threadId: ID!, body: String): EntityResult
register(email: String!, userName: String!, password: String!): String!
login(userName: String!, password: String!): String!
logout(userName: String!): String!
updateThreadPoint(threadId: ID!, increment: Boolean!): String!
updateThreadItemPoint(threadItemId: ID!, increment: Boolean!): String!
changePassword(newPassword: String!): String!
}
`
Example #17
Source File: index.ts From ledokku with MIT License | 4 votes |
typeDefs = gql`
scalar DateTime
type App {
id: ID!
name: String!
createdAt: DateTime!
type: AppTypes!
databases: [Database!]
appMetaGithub: AppMetaGithub
}
type GithubAppInstallationId {
id: String!
}
type AppMetaGithub {
repoId: String!
repoName: String!
repoOwner: String!
branch: String!
githubAppInstallationId: String!
}
type Repository {
id: String!
name: String!
fullName: String!
private: Boolean!
}
type Branch {
name: String!
}
enum AppTypes {
DOKKU
GITHUB
GITLAB
DOCKER
}
type AppBuild {
id: ID!
status: AppBuildStatus!
}
enum AppBuildStatus {
PENDING
IN_PROGRESS
COMPLETED
ERRORED
}
type Database {
id: ID!
name: String!
type: DatabaseTypes!
version: String
createdAt: DateTime!
apps: [App!]
}
enum DatabaseTypes {
REDIS
POSTGRESQL
MONGODB
MYSQL
}
type Domains {
domains: [String!]!
}
type RealTimeLog {
message: String
type: String
}
type LoginResult {
token: String!
}
type RegisterGithubAppResult {
githubAppClientId: String!
}
type CreateAppDokkuResult {
appId: String!
}
type CreateAppGithubResult {
result: Boolean!
}
type DestroyAppResult {
result: Boolean!
}
type RestartAppResult {
result: Boolean!
}
type RebuildAppResult {
result: Boolean!
}
type DestroyDatabaseResult {
result: Boolean!
}
type LinkDatabaseResult {
result: Boolean!
}
type UnlinkDatabaseResult {
result: Boolean!
}
type DokkuPlugin {
name: String!
version: String!
}
type DokkuPluginResult {
version: String!
plugins: [DokkuPlugin!]!
}
type SetEnvVarResult {
result: Boolean!
}
type UnsetEnvVarResult {
result: Boolean!
}
type CreateDatabaseResult {
result: Boolean!
}
type AppLogsResult {
logs: [String!]!
}
type DatabaseInfoResult {
info: [String!]!
}
type DatabaseLogsResult {
logs: [String]!
}
type IsDatabaseLinkedResult {
isLinked: Boolean!
}
type EnvVar {
key: String!
value: String!
}
type EnvVarsResult {
envVars: [EnvVar!]!
}
type SetDomainResult {
result: Boolean!
}
type AddDomainResult {
result: Boolean!
}
type RemoveDomainResult {
result: Boolean!
}
type SetupResult {
canConnectSsh: Boolean!
sshPublicKey: String!
isGithubAppSetup: Boolean!
githubAppManifest: String!
}
type IsPluginInstalledResult {
isPluginInstalled: Boolean!
}
type AppProxyPort {
scheme: String!
host: String!
container: String!
}
input CreateAppDokkuInput {
name: String!
}
input CreateAppGithubInput {
name: String!
gitRepoFullName: String!
branchName: String!
gitRepoId: String!
githubInstallationId: String!
}
input RestartAppInput {
appId: String!
}
input RebuildAppInput {
appId: String!
}
input CreateDatabaseInput {
name: String!
type: DatabaseTypes!
}
input UnlinkDatabaseInput {
appId: String!
databaseId: String!
}
input SetEnvVarInput {
appId: String!
key: String!
value: String!
}
input UnsetEnvVarInput {
appId: String!
key: String!
}
input DestroyAppInput {
appId: String!
}
input AddDomainInput {
appId: String!
domainName: String!
}
input RemoveDomainInput {
appId: String!
domainName: String!
}
input SetDomainInput {
appId: String!
domainName: String!
}
input LinkDatabaseInput {
appId: String!
databaseId: String!
}
input DestroyDatabaseInput {
databaseId: String!
}
input AddAppProxyPortInput {
appId: String!
host: String!
container: String!
}
input RemoveAppProxyPortInput {
appId: String!
scheme: String!
host: String!
container: String!
}
type Query {
githubInstallationId: GithubAppInstallationId!
setup: SetupResult!
apps: [App!]!
repositories(installationId: String!): [Repository!]!
branches(repositoryName: String!, installationId: String!): [Branch!]!
appMetaGithub(appId: String!): AppMetaGithub
app(appId: String!): App
domains(appId: String!): Domains!
database(databaseId: String!): Database
databases: [Database!]!
isPluginInstalled(pluginName: String!): IsPluginInstalledResult!
dokkuPlugins: DokkuPluginResult!
appLogs(appId: String!): AppLogsResult!
databaseInfo(databaseId: String!): DatabaseInfoResult!
databaseLogs(databaseId: String!): DatabaseLogsResult!
isDatabaseLinked(
databaseId: String!
appId: String!
): IsDatabaseLinkedResult!
envVars(appId: String!): EnvVarsResult!
appProxyPorts(appId: String!): [AppProxyPort!]!
}
type Subscription {
unlinkDatabaseLogs: RealTimeLog!
linkDatabaseLogs: RealTimeLog!
createDatabaseLogs: RealTimeLog!
appRestartLogs: RealTimeLog!
appRebuildLogs: RealTimeLog!
appCreateLogs: RealTimeLog!
}
type Mutation {
loginWithGithub(code: String!): LoginResult
registerGithubApp(code: String!): RegisterGithubAppResult
addDomain(input: AddDomainInput!): AddDomainResult!
removeDomain(input: RemoveDomainInput!): RemoveDomainResult!
setDomain(input: SetDomainInput!): SetDomainResult!
createAppDokku(input: CreateAppDokkuInput!): CreateAppDokkuResult!
createDatabase(input: CreateDatabaseInput!): CreateDatabaseResult!
setEnvVar(input: SetEnvVarInput!): SetEnvVarResult!
unsetEnvVar(input: UnsetEnvVarInput!): UnsetEnvVarResult!
destroyApp(input: DestroyAppInput!): DestroyAppResult!
restartApp(input: RestartAppInput!): RestartAppResult!
rebuildApp(input: RebuildAppInput!): RebuildAppResult!
destroyDatabase(input: DestroyDatabaseInput!): DestroyDatabaseResult!
linkDatabase(input: LinkDatabaseInput!): LinkDatabaseResult!
unlinkDatabase(input: UnlinkDatabaseInput!): UnlinkDatabaseResult!
addAppProxyPort(input: AddAppProxyPortInput!): Boolean
removeAppProxyPort(input: RemoveAppProxyPortInput!): Boolean
createAppGithub(input: CreateAppGithubInput!): CreateAppGithubResult!
}
`