Skip to content

Instantly share code, notes, and snippets.

View HarisSpahija's full-sized avatar
🏗️
Constructing Code

Haris Spahija HarisSpahija

🏗️
Constructing Code
View GitHub Profile
@HarisSpahija
HarisSpahija / bem-name-required.js
Created March 21, 2023 14:11
Custom Stylelint test for BEM
const stylelint = require("stylelint");
const { report, ruleMessages, validateOptions } = stylelint.utils;
const ruleName = "w3s-stylelint-plugin/force-bem-class-selector";
const messages = ruleMessages(ruleName, {
expected: (unfixed, fixed) =>
`"${unfixed}" is not a valid BEM class name "${fixed}"`,
});
module.exports = stylelint.createPlugin(
@HarisSpahija
HarisSpahija / getSlogan.query
Created May 20, 2020 21:21
Query for getSlogan
query {
getSlogan(language: en) {
slogan
language
}
}
// Returns
{
"data": {
@HarisSpahija
HarisSpahija / getSlogan.js
Created May 20, 2020 21:20
src/graphql/resolvers/Query/getSlogan.js
/**
* @name Query/hybrit
* @method
* @memberof GraphQL/ExampleTemplateCollection/Query
* @summary query hybrit and return its slogan
* @param {Object} _ - unused
* @param {Object} args - an object of all arguments that were sent by the client
* @param {String} args.language - language that needs to be selected
* @param {Object} context - an object containing the per-request state
* @param {Object} info Info about the GraphQL request
@HarisSpahija
HarisSpahija / getSlogan.js
Created May 20, 2020 21:14
src/graphql/quries/getSlogan.js
/**
* @name getSlogan
* @method
* @memberof GraphQL/ExampleTemplateCollection
* @summary Query the slogan based on the right langauge
* @param {Object} context - an object containing the per-request state
* @param {String} language - Language that needs to be returned
*/
export default async function getSlogan(context, languageCode) {
// We can find our collection by looking into context
@HarisSpahija
HarisSpahija / index.js
Created May 20, 2020 17:17
src/graphql/schemas/index.js
import importAsString from "@reactioncommerce/api-utils/importAsString.js";
const schema = importAsString("./schema.graphql");
export default [schema];
@HarisSpahija
HarisSpahija / schema.graphql
Last active May 20, 2020 17:27
src/graphql/schemas/schema.graphql
"enum for language"
enum Language {
en
nl
de
esp
bih
}
type Slogan {
@HarisSpahija
HarisSpahija / seedExampleTemplate.js
Created May 20, 2020 14:55
util/seedExampleTemplate.js
import Logger from "@reactioncommerce/logger";
import Random from "@reactioncommerce/random";
/**
* @param {Object} ExampleTemplateCollection Collection that will be seeded into
* @param {String} translationObject Object that contains our translation
* @returns {undefined}
*/
export default async function seedExampleTemplateCollection(
ExampleTemplateCollection,
@HarisSpahija
HarisSpahija / seedExampleTemplateCollection.js
Created May 20, 2020 14:54
util/seedExampleTemplateCollection.js
import translationsFile from "../i18n/index.js";
import seedExampleTemplate from "./seedExampleTemplate.js";
/**
* @summary Creates a collection of translations used for our Example.
* @param {Object} ExampleTemplateCollection MongoDB collection that will be seeded into
* @returns {undefined}
*/
export default async function seedExampleTemplateCollection(ExampleTemplateCollection) {
@HarisSpahija
HarisSpahija / startup.js
Created May 20, 2020 14:50
src/startup.js
// In this file, everything that requires to be done on startup can be done
// This can be for example setting up a collection or seeding data
// Note that this fuction wil run every single time when starting the project up with docker-compose in dev mode.
import Logger from "@reactioncommerce/logger";
import seedExampleTemplateCollection from "./util/seedExampleTemplateCollection.js"
/**
* @name startup
* @summary Called on startup
* @param {Object} context App context
* @returns {undefined}
@HarisSpahija
HarisSpahija / index.js
Created May 20, 2020 14:45
src/index.js
import startup from "./startup.js";
/**
* @summary Import and call this function to add this plugin to your API.
* @param {ReactionAPI} app ReactionAPI instance
* @returns {undefined}
*/
export default async function register(app) {
/**
* Simple Ping Pong like example plugin